/org-mime

org-mime can be used to send HTML email using Org-mode HTML export.

Primary LanguageEmacs Lisp

org-mime v0.1.1

org-mime can be used to send HTML email using Org-mode HTML export.

This approximates a WYSiWYG HTML mail editor from within Emacs, and can be useful for sending tables, fontified source code, and inline images in email.

Tested on Emacs 24.3, 24.4, 24.5, 25.1, 25.2

Setup

(require 'org-mime)
;; for gnus – this is set by default
(setq org-mime-library 'mml)
;; OR for Wanderlust (WL)
;; (setq org-mime-library 'semi)
;; OR for VM – not yet supported
;; (setq org-mime-library 'vm)

Usage

M-x org-mime-htmlize

M-x org-mime-htmlize from within a mail composition buffer to export either the entire buffer or just the active region to html, and embed the results into the buffer as a text/html mime section.

Export a portion of an email body composed using `mml-mode’ to html using `org-mode’. If called with an active region only export that region, otherwise export the entire body.

Warning: There has been some concern voiced over the potential complexity of email resulting from calling this function on an active region resulting in multiple multipart/alternative sections in the same email. Please see this email thread for a discussion of the potential pitfalls of this approach. Speaking from personal experience this has not been a problem for the author.

M-x org-mime-org-buffer-htmlize

org-mime-org-buffer-htmlize can be called from within an Org-mode buffer to export either the whole buffer or the narrowed subtree or active region to HTML, and open a new email buffer including the resulting HTML content as an embedded mime section.

Export the current org-mode buffer to HTML using org-export-as-html and package the results into an email handling with appropriate MIME encoding.

The following key bindings are suggested, which bind the C-c M-o key sequence to the appropriate org-mime function in both email and Org-mode buffers,

(add-hook 'message-mode-hook
          (lambda ()
            (local-set-key (kbd "C-c M-o") 'org-mime-htmlize)))
(add-hook 'org-mode-hook
          (lambda ()
            (local-set-key (kbd "C-c M-o") 'org-mime-org-buffer-htmlize)))

M-x org-mime-org-subtree-htmlize

org-mime-org-subtree-htmlize is similar to org-mime-org-buffer-htmlize but works on subtree. It can also read subtree properties MAIL_SUBJECT, MAIL_TO, MAIL_CC, and MAIL_BCC. Here is the sample of subtree:

* mail one
 :PROPERTIES:
 :MAIL_SUBJECT: mail title
 :MAIL_TO: person1@gmail.com
 :MAIL_CC: person2@gmail.com
 :MAIL_BCC: person3@gmail.com
 :END:
content ...

Tips

Embed image into mail body

Use below syntax,

[[/full/path/to/your.jpg]]

CSS style customization

Email clients will often strip all global CSS from email messages. In the case of web-based email readers this is essential in order to protect the CSS of the containing web site. To ensure that your CSS styles are rendered correctly they must be included in the actual body of the elements to which they apply.

The `org-mime-html-hook’ allows for the insertion of these important CSS elements into the resulting HTML before mime encoding. The following are some possible uses of this hook.

For those who use color themes with Dark backgrounds it is useful to set a dark background for all exported code blocks and example regions. This can be accomplished with the following,

(add-hook 'org-mime-html-hook
          (lambda ()
            (org-mime-change-element-style
             "pre" (format "color: %s; background-color: %s; padding: 0.5em;"
                           "#E6E1DC" "#232323"))))

;; the following can be used to nicely offset block quotes in email bodies
(add-hook 'org-mime-html-hook
          (lambda ()
            (org-mime-change-element-style
             "blockquote" "border-left: 2px solid gray; padding-left: 4px;")))

Render text between “@” in red color, you can use `org-mime-html-hook’,

(add-hook 'org-mime-html-hook
          (lambda ()
            (while (re-search-forward "@\\([^@]*\\)@" nil t)
              (replace-match "<span style=\"color:red\">\\1</span>"))))

For other customization options see the org-mime customization group.

Beautify quoted mail when replying

It already works out of box. Currently it emulate Gmail’s style. You can go back the old Gnus style by (setq org-mime-beautify-quoted-mail nil).

Export options

To avoid exporting TOC, you can setup `org-mime-export-options’,

(setq org-mime-export-options '(:section-numbers nil
                                :with-author nil
                                :with-toc nil))

Or just setup your export options in org buffer/subtree.

`org-mime-export-options’ will override your export options if it’s NOT nil.

Keep gpg signatures outside of multipart

org-mime-find-html-start gives user a chance to tweak the region beginning to htmlize,

(setq org-mime-find-html-start
      (lambda (start)
        (save-excursion
          (goto-char start)
          (search-forward "<#secure method=pgpmime mode=sign>")
          (+ (point) 1))))

Development

  • Patches are always welcomed
  • You can (setq org-mime-debug t) to enable the log
  • Make sure your code has minimum dependency and works on Emacs versions we support

Credits

  • org-mime was developed by Eric Schulte with much-appreciated help and discussion from everyone on the using orgmode to send html mail thread especially Eric S. Fraga for adding WL support.
  • Anthony Cowley fixed many bugs for exporting
  • Matt Price improved handling of mail headers (CC, BCC …)

Report bug

You need provides the version of Emacs and Org-mode you are using.

We also need exact steps to reproduce the issue.

Licence

Documentation from the http://orgmode.org/worg/ website (either in its HTML format or in its Org format) is licensed under the GNU Free Documentation License version 1.3 or later. The code examples and css style sheets are licensed under the GNU General Public License v3 or later.