Skip to content

Latest commit

 

History

History
141 lines (83 loc) · 3.84 KB

Emacs-Mail-04.org

File metadata and controls

141 lines (83 loc) · 3.84 KB

Enhance Your Emails with Org Mode

Org Mode is great for email too!

  • Composing HTML-formatted email messages
  • Attaching images inline
  • Sending the contents of your existing Org files
  • Writing e-mails in Org files to send later

Sending HTML mail

We can use the org-mime package for this purpose:

(use-package org-mime
  :ensure t)

Now you can use M-x org-mime-htmlize inside of a mail composition buffer to convert it to HTML!

You can include:

  • Formatted text (bold, italic, etc)
  • Headings and subheadings
  • Links
  • Code blocks
  • Images (that get attached correctly)
  • … anything that org-mode can convert to HTML
* First heading!

Check out [[https://github.com/org-mime/org-mime][org-mime]]

** Here's some Emacs Lisp


  (setq it-works t)

  (defun does-it-work ()
    (when it-works
      (message "It works!")))

+end_src

Enjoy this huge Emacs logo:

[[~/Downloads/1024px-EmacsIcon.svg.png]]

*Very cool!*

NOTE: Don’t forget to add the # before the +end_src if you copy/paste this block!

Composing Org mail comfortably

This required us to type out raw Org into the composition buffer. What if we want to write in Org Mode?

Run M-x org-mime-edit-mail-in-org-mode

This didn’t automatically convert our mail body to HTML though! Still need to run M-x org-mime-htmlize before sending.

Sending an existing Org buffer or subtree as e-mail

You can use the following functions to send an existing org-mode document as an e-mail message:

  • org-mime-org-buffer-htmlize - Send an entire org-mode buffer as an e-mail message
  • org-mime-org-subtree-htmlize - Send a subtree of the current org-mode buffer as an e-mail message

This will open up a new mail composition view, but it seems to use the default compose function instead of mu4e! You may need to run M-x mu4e-compose-mode to set the buffer to use mu4e’s behavior.

One interesting aspect of the subtree function is that you can configure the e-mail using Org properties:

* Mail message
:PROPERTIES:
:MAIL_SUBJECT: I wrote this in Org Mode!
:MAIL_TO: [email protected]
:MAIL_CC: [email protected]
:MAIL_BCC: [email protected]
:END:

Here is the body of the message!

This would allow you to compose Org-formatted e-mails in advance and then send them when you are ready.

Customizing the HTML export style

As you might have noticed, the exported e-mail has section numbers for headings. We can turn that off!

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

org-mime starts with Org’s configured export options for HTML so your defaults may be different.

We can also customize the styling of individual HTML elements inside of the message using org-mime-html-hook. Here’s an example of making all code blocks have a dark background and light text:

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

Automatically converting mail to HTML

You can easily add a hook to do this conversion for you automatically:

(add-hook 'message-send-hook 'org-mime-htmlize)

Alternatively if you just want be reminded when you didn’t use HTML, use org-mime-confirm-when-no-multipart:

(add-hook 'message-send-hook 'org-mime-confirm-when-no-multipart)

What’s next?

Next time we’ll talk about how you can use Org Mode to manage your email processing workflow using capture templates!