<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <atom:link href="http://kitchingroup.cheme.cmu.edu/blog/feed/index.xml" rel="self" type="application/rss+xml" />
    <title>The Kitchin Research Group</title>
    <link>https://kitchingroup.cheme.cmu.edu/blog</link>
    <description>Chemical Engineering at Carnegie Mellon University</description>
    <pubDate>Sat, 01 Nov 2025 13:47:46 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    
    <item>
      <title>Sending html emails from org-mode with org-mime</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2016/10/29/Sending-html-emails-from-org-mode-with-org-mime</link>
      <pubDate>Sat, 29 Oct 2016 14:33:16 EDT</pubDate>
      <category><![CDATA[email]]></category>
      <category><![CDATA[orgmode]]></category>
      <guid isPermaLink="false">VN_iXILZVA_93leoZnksFW8pzQs=</guid>
      <description>Sending html emails from org-mode with org-mime</description>
      <content:encoded><![CDATA[


&lt;div id="table-of-contents"&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id="text-table-of-contents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#orgheadline10"&gt;1. From an org-headline in an org-file&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#orgheadline3"&gt;1.1. Markup&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#orgheadline4"&gt;1.2. Equations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#orgheadline5"&gt;1.3. Tables&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#orgheadline6"&gt;1.4. Lists&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#orgheadline7"&gt;1.5. Code block&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#orgheadline8"&gt;1.6. An image from somewhere other than this directory&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#orgheadline9"&gt;1.7. Citations with org-ref&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#orgheadline2"&gt;2. In a mail message&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#orgheadline1"&gt;3. Equations and file attachments do not seem to work out of the box&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#orgheadline11"&gt;4. Summary&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
On the org-mode mailing list there was some discussion about sending html mail using orgmode. The support for this in mu4e is deprecated. There is the org-mime library though, and it supports a lot of what is needed for this. As I played around with it though, I came across some limitations:
&lt;/p&gt;

&lt;ol class="org-ol"&gt;
&lt;li&gt;I found equations were not rendered as images in the html, and files (in links) were not attached out of the box. I fixed that &lt;a href="#orgheadline1"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;I found it useful to modify the org-mime commands to leave point in the To: field when composing emails from org-buffers.&lt;/li&gt;
&lt;li&gt;For use with mu4e, I created a function to open a message in org-mu4e-compose-org-mode, and added a C-cC-c hook to allow me to send it easily &lt;a href="#orgheadline2"&gt;(here)&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
This post documents some work I did figuring out how to send html mails. After some testing, some of these should probably be patched in org-mime.
&lt;/p&gt;

&lt;p&gt;
First, you need to require this library.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;require&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;org-mime&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
You can send a whole org buffer in html like with this command: &lt;a href="org-mime-org-buffer-htmlize"&gt;org-mime-org-buffer-htmlize&lt;/a&gt;. Not all of the internal links work for me (at least in gmail).
&lt;/p&gt;

&lt;p&gt;
The default behavior leaves you at the end of the buffer, which is not too nice. We lightly modify the function here to leave in the To: field.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;org-mime-org-buffer-htmlize&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Create an email buffer containing the current org-mode file&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;  exported to html and encoded in both html and in org formats as&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;  mime alternatives."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (org-mime-send-buffer 'html)
  (message-goto-to))
&lt;/pre&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline10" class="outline-2"&gt;
&lt;h2 id="orgheadline10"&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; From an org-headline in an org-file&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
You can compose an email as an org-heading in any org-buffer, and send it as html. In an org-heading, you need to specify a MAIL_FMT property of html, e.g.:
&lt;/p&gt;

&lt;pre class="example"&gt;
   :PROPERTIES:
   :MAIL_FMT: html
   :END:
&lt;/pre&gt;

&lt;p&gt;
Note the following properties can also be set to modify the composed email.
&lt;/p&gt;
&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;           (subject (&lt;span style="color: #0000FF;"&gt;or&lt;/span&gt; (funcall mp &lt;span style="color: #008000;"&gt;"MAIL_SUBJECT"&lt;/span&gt;) (nth 4 (org-heading-components))))
           (to (funcall mp &lt;span style="color: #008000;"&gt;"MAIL_TO"&lt;/span&gt;))
           (cc (funcall mp &lt;span style="color: #008000;"&gt;"MAIL_CC"&lt;/span&gt;))
           (bcc (funcall mp &lt;span style="color: #008000;"&gt;"MAIL_BCC"&lt;/span&gt;))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Then, send it with &lt;a href="org-mime-subtree"&gt;org-mime-subtree&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
Here I modify this function to leave me in the To: field.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;org-mime-subtree&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Create an email buffer containing the current org-mode subtree&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;  exported to a org format or to the format specified by the&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;  MAIL_FMT property of the subtree."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (org-mime-send-subtree
   (&lt;span style="color: #0000FF;"&gt;or&lt;/span&gt; (org-entry-get nil &lt;span style="color: #008000;"&gt;"MAIL_FMT"&lt;/span&gt; org-mime-use-property-inheritance) 'org))
  (message-goto-to))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Here are some sample elements to see if they convert to html reasonably.
&lt;/p&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline3" class="outline-3"&gt;
&lt;h3 id="orgheadline3"&gt;&lt;span class="section-number-3"&gt;1.1&lt;/span&gt; Markup&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1-1"&gt;
&lt;p&gt;
&lt;b&gt;bold&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;span class="underline"&gt;underlined&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;italics&lt;/i&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;del&gt;strikethrough&lt;/del&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;code&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
Subscripts: H&lt;sub&gt;2&lt;/sub&gt;O
Superscripts: H&lt;sup&gt;+&lt;/sup&gt;
An entity: To &amp;infin; and beyond
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline4" class="outline-3"&gt;
&lt;h3 id="orgheadline4"&gt;&lt;span class="section-number-3"&gt;1.2&lt;/span&gt; Equations&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1-2"&gt;
&lt;p&gt;
\(x^2\)
&lt;/p&gt;

&lt;p&gt;
\[x^4\]
&lt;/p&gt;

&lt;p&gt;
\(e^x\)
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline5" class="outline-3"&gt;
&lt;h3 id="orgheadline5"&gt;&lt;span class="section-number-3"&gt;1.3&lt;/span&gt; Tables&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1-3"&gt;
&lt;table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"&gt;
&lt;caption class="t-above"&gt;&lt;span class="table-number"&gt;Table 1:&lt;/span&gt; A table for you.&lt;/caption&gt;

&lt;colgroup&gt;
&lt;col  class="org-right" /&gt;

&lt;col  class="org-right" /&gt;
&lt;/colgroup&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="org-right"&gt;x&lt;/td&gt;
&lt;td class="org-right"&gt;y&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td class="org-right"&gt;1&lt;/td&gt;
&lt;td class="org-right"&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline6" class="outline-3"&gt;
&lt;h3 id="orgheadline6"&gt;&lt;span class="section-number-3"&gt;1.4&lt;/span&gt; Lists&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1-4"&gt;
&lt;p&gt;
A nested list.
&lt;/p&gt;
&lt;ul class="org-ul"&gt;
&lt;li&gt;one
&lt;ul class="org-ul"&gt;
&lt;li&gt;Subentry under one.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;two&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;
A definition list:
&lt;/p&gt;

&lt;dl class="org-dl"&gt;
&lt;dt&gt;def1&lt;/dt&gt;&lt;dd&gt;first definition&lt;/dd&gt;
&lt;/dl&gt;

&lt;p&gt;
A checklist:
&lt;/p&gt;
&lt;ul class="org-ul"&gt;
&lt;li class="off"&gt;&lt;code&gt;[&amp;#xa0;]&lt;/code&gt; A checkbox&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;
Here is a numbered list:
&lt;/p&gt;

&lt;ol class="org-ol"&gt;
&lt;li&gt;number 1&lt;/li&gt;
&lt;li&gt;number 2&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline7" class="outline-3"&gt;
&lt;h3 id="orgheadline7"&gt;&lt;span class="section-number-3"&gt;1.5&lt;/span&gt; Code block&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1-5"&gt;
&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; numpy &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; np
&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; plt

&lt;span style="color: #BA36A5;"&gt;t&lt;/span&gt; = np.linspace(0, 10)
&lt;span style="color: #BA36A5;"&gt;x&lt;/span&gt; = np.cos(t) * np.exp(-t)
&lt;span style="color: #BA36A5;"&gt;y&lt;/span&gt; = np.sin(t) * np.exp(-t)

plt.plot(x, y)
plt.savefig(&lt;span style="color: #008000;"&gt;'spiral.png'&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
&lt;img src="/media/spiral.png"&gt; 
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline8" class="outline-3"&gt;
&lt;h3 id="orgheadline8"&gt;&lt;span class="section-number-3"&gt;1.6&lt;/span&gt; An image from somewhere other than this directory&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1-6"&gt;
&lt;p&gt;
&lt;img src="/media/Au-icosahedron-3.png"&gt; 
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline9" class="outline-3"&gt;
&lt;h3 id="orgheadline9"&gt;&lt;span class="section-number-3"&gt;1.7&lt;/span&gt; Citations with org-ref&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1-7"&gt;
&lt;table id="orgtable1" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"&gt;


&lt;colgroup&gt;
&lt;col  class="org-left" /&gt;

&lt;col  class="org-left" /&gt;

&lt;col  class="org-left" /&gt;
&lt;/colgroup&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="org-left"&gt;a&lt;/td&gt;
&lt;td class="org-left"&gt;b&lt;/td&gt;
&lt;td class="org-left"&gt;c&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;
See Table &lt;a href="#table-1"&gt;table-1&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
&lt;a class='org-ref-reference' href="#Dominik201408"&gt;Dominik201408&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;h1 class='org-ref-bib-h1'&gt;Bibliography&lt;/h1&gt;
&lt;ul class='org-ref-bib'&gt;&lt;li&gt;&lt;a id="Dominik201408"&gt;[Dominik201408] Carsten Dominik, The Org Mode 8 Reference Manual - Organize your life with GNU  Emacs, Samurai Media Limited (2014).&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline2" class="outline-2"&gt;
&lt;h2 id="orgheadline2"&gt;&lt;a id="ID-D44F059D-180C-41C5-BA0A-873723E0DDFB"&gt;&lt;/a&gt;&lt;span class="section-number-2"&gt;2&lt;/span&gt; In a mail message&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-2"&gt;
&lt;p&gt;
You might prefer to do this directly in an email. Here is how you can do it in mu4e. I use this command to open a message in org-mode. The mode switches if you are in the header, or in the body. If you always do this, you could use a hook instead on message-mode. I do not want default html so I do not do it. 
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;mu4e-compose-org-mail&lt;/span&gt; ()
 (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
 (mu4e-compose-new)
 (org-mu4e-compose-org-mode))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
For sending, we will use org-mime to htmlize it, and add a C-c C-c hook function to send it.  This hook is a little tricky, we want to preserve C-c C-c behavior in org-mode, e.g. in code blocks, but send it if there is no other C-c C-c action that makes sense, so we add it to the end of the hook. Alternatively, you could bind a special key for it, or run the special command. Note the C-c C-c hook only works in the body of the email. From the header, a plain text message is sent.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;htmlize-and-send&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"When in an org-mu4e-compose-org-mode message, htmlize and send it."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (member 'org~mu4e-mime-switch-headers-or-body post-command-hook)
    (org-mime-htmlize) 
    (message-send-and-exit)))

(add-hook 'org-ctrl-c-ctrl-c-hook 'htmlize-and-send t)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Here is a way to do this for non-mu4e users. It doesn't have the nice mode switching capability though, so you lose completion in emails, and header specific functions. You can switch back to message-mode to regain those.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;compose-html-org&lt;/span&gt; ()
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (compose-mail)
  (message-goto-body)
  (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; *compose-html-org* t)
  (org-mode))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;org-htmlize-and-send&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"When in an org-mu4e-compose-org-mode message, htmlize and send it."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  
  (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; *compose-html-org*
    (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; *compose-html-org* nil)
    (message-mode)
    (org-mime-htmlize) 
    (message-send-and-exit)))

(add-hook 'org-ctrl-c-ctrl-c-hook 'org-htmlize-and-send t)
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline1" class="outline-2"&gt;
&lt;h2 id="orgheadline1"&gt;&lt;a id="ID-14317E51-C65E-48DD-9B52-B94D6B458E8F"&gt;&lt;/a&gt;&lt;span class="section-number-2"&gt;3&lt;/span&gt; Equations and file attachments do not seem to work out of the box&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-3"&gt;
&lt;p&gt;
\(e^{i\pi} - 1 = 0\)
&lt;/p&gt;

&lt;p&gt;
Out of the box, org-mime does not seem to attach file links to emails or make images for equations..
&lt;/p&gt;

&lt;p&gt;
&lt;a href="/media/html-email.org"&gt;html-email.org&lt;/a&gt; 
&lt;/p&gt;

&lt;p&gt;
Here is an adaptation of org-mime-compose that does that for html messages.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;org-mime-compose&lt;/span&gt; (body fmt file &lt;span style="color: #6434A3;"&gt;&amp;amp;optional&lt;/span&gt; to subject headers)
  (&lt;span style="color: #0000FF;"&gt;require&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;message&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((bhook
         (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (body fmt)
           (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((hook (intern (concat &lt;span style="color: #008000;"&gt;"org-mime-pre-"&lt;/span&gt;
                                       (symbol-name fmt)
                                       &lt;span style="color: #008000;"&gt;"-hook"&lt;/span&gt;))))
             (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (&amp;gt; (eval `(length ,hook)) 0)
                 (&lt;span style="color: #0000FF;"&gt;with-temp-buffer&lt;/span&gt;
                   (insert body)
                   (goto-char (point-min))
                   (eval `&lt;span style="color: #D0372D;"&gt;(run-hooks &lt;/span&gt;',hook))
                   (buffer-string))
               body))))
        (fmt (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (symbolp fmt) fmt (intern fmt)))
        (files (org-element-map (org-element-parse-buffer) 'link
                 (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (link)
                   (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (string= (org-element-property &lt;span style="color: #006FE0;"&gt;:type&lt;/span&gt; link) &lt;span style="color: #008000;"&gt;"file"&lt;/span&gt;)
                     (file-truename (org-element-property &lt;span style="color: #006FE0;"&gt;:path&lt;/span&gt; link)))))))
    (compose-mail to subject headers nil)
    (message-goto-body)
    (&lt;span style="color: #0000FF;"&gt;cond&lt;/span&gt;
     ((eq fmt 'org)
      (&lt;span style="color: #0000FF;"&gt;require&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;ox-org&lt;/span&gt;)
      (insert (org-export-string-as
               (org-babel-trim (funcall bhook body 'org)) 'org t)))
     ((eq fmt 'ascii)
      (&lt;span style="color: #0000FF;"&gt;require&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;ox-ascii&lt;/span&gt;)
      (insert (org-export-string-as
               (concat &lt;span style="color: #008000;"&gt;"#+Title:\n"&lt;/span&gt; (funcall bhook body 'ascii)) 'ascii t)))
     ((&lt;span style="color: #0000FF;"&gt;or&lt;/span&gt; (eq fmt 'html) (eq fmt 'html-ascii))
      (&lt;span style="color: #0000FF;"&gt;require&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;ox-ascii&lt;/span&gt;)
      (&lt;span style="color: #0000FF;"&gt;require&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;ox-org&lt;/span&gt;)
      (&lt;span style="color: #0000FF;"&gt;let*&lt;/span&gt; ((org-link-file-path-type 'absolute)
             &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;we probably don't want to export a huge style file&lt;/span&gt;
             (org-export-htmlize-output-type 'inline-css)
             (org-html-with-latex 'dvipng)
             (html-and-images
              (org-mime-replace-images
               (org-export-string-as (funcall bhook body 'html) 'html t)))
             (images (cdr html-and-images))
             (html (org-mime-apply-html-hook (car html-and-images))))
        (insert (org-mime-multipart
                 (org-export-string-as
                  (org-babel-trim
                   (funcall bhook body (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (eq fmt 'html) 'org 'ascii)))
                  (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (eq fmt 'html) 'org 'ascii) t)
                 html)
                (mapconcat 'identity images &lt;span style="color: #008000;"&gt;"\n"&lt;/span&gt;)))))
    (mapc #'mml-attach-file files)))
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgheadline11" class="outline-2"&gt;
&lt;h2 id="orgheadline11"&gt;&lt;span class="section-number-2"&gt;4&lt;/span&gt; Summary&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-4"&gt;
&lt;p&gt;
This makes it pretty nice to send rich-formatted html text to people.
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2016 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;
&lt;p&gt;&lt;a href="/org/2016/10/29/Sending-html-emails-from-org-mode-with-org-mime.org"&gt;org-mode source&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Org-mode version = 8.3.5&lt;/p&gt;]]></content:encoded>
    </item>
    <item>
      <title>Checking for email attachments before you send email</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2015/09/04/Checking-for-email-attachments-before-you-send-email</link>
      <pubDate>Fri, 04 Sep 2015 19:03:53 EDT</pubDate>
      <category><![CDATA[email]]></category>
      <category><![CDATA[emacs]]></category>
      <guid isPermaLink="false">MErOMYWf44oQU2aj5jMLXAC9izU=</guid>
      <description>Checking for email attachments before you send email</description>
      <content:encoded><![CDATA[


&lt;p&gt;
Does this comic (&lt;a href="http://www.phdcomics.com/comics/archive.php?comicid=1817"&gt;http://www.phdcomics.com/comics/archive.php?comicid=1817&lt;/a&gt; ) apply to you? Do you miss the Gmail feature that will alert you that it seems like you mention an attachment but there isn't one attached before it lets you send it? Let's make Emacs help us here. We will scan our emails for the word "attach", and if we see it, scan the email for evidence of an attachment. Then create a hook function that will prompt us if it appears we mention an attachment, but don't have one.
&lt;/p&gt;

&lt;p&gt;
An attachment looks like this in my messages:
&lt;/p&gt;
&lt;pre class="example"&gt;
&amp;lt;#part type="image/png" filename="~/Desktop/wordcloud.png" disposition=attachment&amp;gt;
&amp;lt;#/part&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
So, probably finding "&amp;lt;#part" in the buffer means I probably have an attachment. We will use the message-send-hook to run this function. Here is the code. Some brief testing from me seems to work fine! It is pretty simple, but probably good enough to save me from sending messages with no attachment, and not too intrusive for when no attachment is actually needed, e.g. in replies. Let me know if you have ideas for improvements.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;email-says-attach-p&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Return t if email suggests there could be an attachment."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;save-excursion&lt;/span&gt;
    (goto-char (point-min))
    (re-search-forward &lt;span style="color: #008000;"&gt;"attach"&lt;/span&gt; nil t)))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;email-has-attachment-p&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Return t if the currently open email has an attachment"&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;save-excursion&lt;/span&gt;
    (goto-char (point-min))
    (re-search-forward &lt;span style="color: #008000;"&gt;"&amp;lt;#part"&lt;/span&gt; nil t)))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;email-pre-send-check-attachment&lt;/span&gt; ()
  (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt; (email-says-attach-p)
             (not (email-has-attachment-p)))
    (&lt;span style="color: #0000FF;"&gt;unless&lt;/span&gt;
        (y-or-n-p &lt;span style="color: #008000;"&gt;"Your email suggests you need an attachment, but no attachment was found. Send anyway?"&lt;/span&gt;)
      (&lt;span style="color: #ff0000; font-weight: bold;"&gt;error&lt;/span&gt; &lt;span style="color: #008000;"&gt;"It seems an attachment is needed, but none was found. Aborting send."&lt;/span&gt;))))

(add-hook 'message-send-hook 'email-pre-send-check-attachment)
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2015 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2015/09/04/Checking-for-email-attachments-before-you-send-email.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.10&lt;/p&gt;]]></content:encoded>
    </item>
    <item>
      <title>Clickable email addresses in emacs</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2015/06/21/Clickable-email-addresses-in-emacs</link>
      <pubDate>Sun, 21 Jun 2015 16:42:40 EDT</pubDate>
      <category><![CDATA[email]]></category>
      <category><![CDATA[emacs]]></category>
      <guid isPermaLink="false">yQhR3CKLJrKAF-nSLoMLoxU0VgA=</guid>
      <description>Clickable email addresses in emacs</description>
      <content:encoded><![CDATA[



&lt;p&gt;
There are clickable &lt;a href="mailto:jkitchin@andrew.cmu.edu"&gt;mailto:jkitchin@andrew.cmu.edu&lt;/a&gt; links in org-mode, but standalone email addresses like jkitchin@cmu.edu are just ordinary text. Here, I want to explore using clickable text instead. I will use the button-lock package for this. I borrowed an email regexp from &lt;a href="http://www.emacswiki.org/emacs/RegularExpression"&gt;EmacsWiki: Regular Expression&lt;/a&gt; for this. The idea is to define a regular expression for an email address, and use it to make the emails clickable.
&lt;/p&gt;

&lt;p&gt;
I am still not sure what the canonical way to get the value of the text that was highlighted. Here we use the :additional-property feature to set a property to t, and then use that property to get the characters that have a non-nil "email-address" property. It seems clunky, but it works. The main action is to compose an email in mu4e (my preferred email program in emacs). You could also put a call to helm here, or to a hydra for other options.
&lt;/p&gt;

&lt;p&gt;
I make the email addresses stand out a little by giving them a gray background, and a tooltip so you can see why they are highlighted. I also bind RET so I don't have to use the mouse. Don't forget you can type C-h . to see the local help instead of mousing over it! Finally, we add a text-mode hook so this will get loaded when we open a text file (or one with a mode derived from text-mode like org-mode).
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;highlight-email-addresses&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Add button to email address. Clicking or RET will open a compose email window."&lt;/span&gt;
  (button-lock-set-button
   &lt;span style="color: #008000;"&gt;"\\w+&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;\\&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;(&lt;/span&gt;&lt;span style="color: #008000;"&gt;\\.\\w+&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;\\&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;)&lt;/span&gt;&lt;span style="color: #008000;"&gt;?@&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;\\&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;(&lt;/span&gt;&lt;span style="color: #008000;"&gt;\\w&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;\\&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;|&lt;/span&gt;&lt;span style="color: #008000;"&gt;\\.&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;\\&lt;/span&gt;&lt;span style="color: #008000; font-weight: bold;"&gt;)&lt;/span&gt;&lt;span style="color: #008000;"&gt;+"&lt;/span&gt;
   (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; ()
     (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
     (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((start) (end) (email-address))
       (&lt;span style="color: #0000FF;"&gt;while&lt;/span&gt; (get-text-property (point) 'email-address)
         (backward-char))
       (forward-char)
       (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; start (point))
       (&lt;span style="color: #0000FF;"&gt;while&lt;/span&gt; (get-text-property (point) 'email-address)
         (forward-char))
       (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; end (point))
       (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; email-address (buffer-substring start end))
       (mu4e~compose-mail email-address)))
     &lt;span style="color: #006FE0;"&gt;:face&lt;/span&gt; '((&lt;span style="color: #006FE0;"&gt;:background&lt;/span&gt; &lt;span style="color: #008000;"&gt;"gray80"&lt;/span&gt;) (&lt;span style="color: #006FE0;"&gt;:underline&lt;/span&gt; t))
     &lt;span style="color: #006FE0;"&gt;:help-echo&lt;/span&gt; &lt;span style="color: #008000;"&gt;"click to send mu4e email"&lt;/span&gt;
     &lt;span style="color: #006FE0;"&gt;:keyboard-binding&lt;/span&gt; (kbd &lt;span style="color: #008000;"&gt;"RET"&lt;/span&gt;)
     &lt;span style="color: #006FE0;"&gt;:additional-property&lt;/span&gt; 'email-address))

(add-hook 'text-mode-hook 'highlight-email-addresses)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
That doesn't look too bad. Now, anytime I open an org-mode file with an email address in it, the address is highlighted in light gray, and underlined. I can click on it or put the cursor on it and press return and I get a compose email window open, with the email address pre-filled in! I am sure this will have some other applications.
&lt;/p&gt;
&lt;p&gt;Copyright (C) 2015 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2015/06/21/Clickable-email-addresses-in-emacs.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.10&lt;/p&gt;]]></content:encoded>
    </item>
    <item>
      <title>A helm-mu4e contact selector</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2015/03/14/A-helm-mu4e-contact-selector</link>
      <pubDate>Sat, 14 Mar 2015 10:21:09 EDT</pubDate>
      <category><![CDATA[helm]]></category>
      <category><![CDATA[email]]></category>
      <category><![CDATA[emacs]]></category>
      <guid isPermaLink="false">YlAI6hrApwjWc1WC0qZq1P4Dy1c=</guid>
      <description>A helm-mu4e contact selector</description>
      <content:encoded><![CDATA[


&lt;p&gt;
I have been using &lt;a href="http://www.djcbsoftware.nl/code/mu/mu4e.html"&gt;mu4e&lt;/a&gt; in Emacs for email for about three months now. It is pretty good, and I hardly ever use the gmail web interface any more. The email completion in mu4e is ok, but I am frequently surprised at what it does not find, and totally spoiled by how good Gmail is at this. The built in completion seems to get lost if you don't start the search with the first few letters. Not always, but too often for me. I don't always remember the first letters, and want to search by name, or company. I would love to search by tags in org-contacts. This should be simple in helm, where you can build up candidates with different bits of information. Here I explore a helm interface, which I think might be better than the built in mu4e support, and even be better than gmail.
&lt;/p&gt;

&lt;p&gt;
In my dream email completer, I want some easy way to define my own groups, I want to use org-contacts (and its tags), and I want every email address in the mails I have in my archive as completion candidates.  helm supports multiple sources, so I initially tried a separate source for each of these. Preliminary efforts suggested it is not possible to mark multiple selections from different sources and pass them all to one function. So, we combine all email candidates into one list of (searchable-string . email-address) cons cells. To get an idea of how many contacts we are looking at:
&lt;/p&gt;

&lt;p&gt;
Here is what I have in my org-contacts file:
&lt;/p&gt;
&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(length (org-contacts-db))
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
173
&lt;/pre&gt;

&lt;p&gt;
And here is what mu4e knows about. Interestingly, it takes a while for this variable to get populated because the request is asynchronous. After the first time though it sticks around. I think just opening mu4e will populate this variable.
&lt;/p&gt;
&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(length mu4e~contacts-for-completion)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
12717
&lt;/pre&gt;

&lt;p&gt;
So, I have close to 13,000 potential email addresses to choose from. For my email groups, I will just use a list of cons cells like (group-name . "comma-separated emails"). Then, I will loop through the org-contacts-db and the mu4e completion list to make the helm candidates. Finally, we add some functions to open our org-contact, and to tag org-contacts so it is easier to make groups.
&lt;/p&gt;

&lt;p&gt;
Here is the code I have been using.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;&lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;here we set aliases for groups.&lt;/span&gt;
(setq email-groups
      '((&lt;span style="color: #008000;"&gt;"ms"&lt;/span&gt; . &lt;span style="color: #008000;"&gt;"email1, email2"&lt;/span&gt;)
        (&lt;span style="color: #008000;"&gt;"phd"&lt;/span&gt; . &lt;span style="color: #008000;"&gt;"email3, email4"&lt;/span&gt;)))


(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;org-contacts-open-from-email&lt;/span&gt; (email)
  &lt;span style="color: #036A07;"&gt;"Open org-contact with matching EMAIL. If no match, create new&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;entry with prompts for first and last name."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((contact (&lt;span style="color: #0000FF;"&gt;catch&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;contact&lt;/span&gt;
                   (loop for contact in  (org-contacts-db)
                         do
                         (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (string= email (cdr (assoc &lt;span style="color: #008000;"&gt;"EMAIL"&lt;/span&gt; (elt contact 2))))
                           (&lt;span style="color: #0000FF;"&gt;throw&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;contact&lt;/span&gt; contact))))))

    (&lt;span style="color: #0000FF;"&gt;unless&lt;/span&gt; contact
                (set-buffer (find-file-noselect (ido-completing-read
                                                 &lt;span style="color: #008000;"&gt;"Select org-contact file: "&lt;/span&gt;
                                                 org-contacts-files)))
                (goto-char (point-max))
                (insert (format  &lt;span style="color: #008000;"&gt;"\n* %s %s\n"&lt;/span&gt;
                                 (read-input &lt;span style="color: #008000;"&gt;"First name: "&lt;/span&gt;)
                                 (read-input &lt;span style="color: #008000;"&gt;"Last name: "&lt;/span&gt;)))
                (org-entry-put (point) &lt;span style="color: #008000;"&gt;"EMAIL"&lt;/span&gt; email)
                (save-buffer))

    (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; contact
      (find-file  (cdr (assoc &lt;span style="color: #008000;"&gt;"FILE"&lt;/span&gt; (elt contact 2))))
      (goto-char (elt contact 1))
      (show-subtree))))


(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;org-contacts-tag-selection&lt;/span&gt; (selection)
  &lt;span style="color: #036A07;"&gt;"Prompts you for a tag, and tags each entry in org-contacts&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;that has a matching email in `&lt;/span&gt;&lt;span style="color: #D0372D;"&gt;helm-marked-candidates&lt;/span&gt;&lt;span style="color: #036A07;"&gt;'. Ignore&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;emails that are not in an org-contact file. I am not sure what&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;the best thing to do there is. Probably prompt for a file, and&lt;/span&gt;
&lt;span style="color: #036A07;"&gt;add an entry to the end of it."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;save-excursion&lt;/span&gt;
    (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((tag (read-input &lt;span style="color: #008000;"&gt;"Tag: "&lt;/span&gt;)))
      (loop for email in (helm-marked-candidates)
            do
            (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((contact (&lt;span style="color: #0000FF;"&gt;catch&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;contact&lt;/span&gt;
                             (loop for contact in  (org-contacts-db)
                                   do
                                   (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; (string=
                                          email
                                          (cdr (assoc
                                                &lt;span style="color: #008000;"&gt;"EMAIL"&lt;/span&gt;
                                                (elt contact 2))))
                                     (&lt;span style="color: #0000FF;"&gt;throw&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;contact&lt;/span&gt; contact))))))
              &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;add new contact and tag it&lt;/span&gt;
              (&lt;span style="color: #0000FF;"&gt;unless&lt;/span&gt; contact
                (set-buffer (find-file-noselect (ido-completing-read
                                                 &lt;span style="color: #008000;"&gt;"Select org-contact file: "&lt;/span&gt;
                                                 org-contacts-files)))
                (goto-char (point-max))
                (insert (format  &lt;span style="color: #008000;"&gt;"\n* %s %s\n"&lt;/span&gt;
                                 (read-input &lt;span style="color: #008000;"&gt;"First name: "&lt;/span&gt;)
                                 (read-input &lt;span style="color: #008000;"&gt;"Last name: "&lt;/span&gt;)))
                (org-entry-put (point) &lt;span style="color: #008000;"&gt;"EMAIL"&lt;/span&gt; email)
                (org-set-tags-to (list tag))
                (save-buffer))
              &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;update tags on existing entry&lt;/span&gt;
              (&lt;span style="color: #0000FF;"&gt;when&lt;/span&gt; contact
                (find-file-noselect  (cdr (assoc &lt;span style="color: #008000;"&gt;"FILE"&lt;/span&gt; (elt contact 2))))
                (set-buffer (marker-buffer (elt contact 1)))
                (goto-char (elt contact 1))
                (org-set-tags-to (append (org-get-tags) (list tag)))))))))


(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;j-insert-emails&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Helm interface to email addresses"&lt;/span&gt;
  (interactive)

  (helm &lt;span style="color: #006FE0;"&gt;:sources&lt;/span&gt; `(((name . &lt;span style="color: #008000;"&gt;"Email address candidates"&lt;/span&gt;)
                   (candidates . ,(append
                                   &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;my aliases&lt;/span&gt;
                                   email-groups
                                   &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;org-contacts&lt;/span&gt;
                                   (loop for contact in (org-contacts-db)
                                         collect
                                         (cons (format
                                                &lt;span style="color: #008000;"&gt;"%s %s %s &amp;lt;%s&amp;gt; org-contact"&lt;/span&gt;
                                                (cdr (assoc &lt;span style="color: #008000;"&gt;"FIRSTNAME"&lt;/span&gt; (elt contact 2)))
                                                (cdr (assoc &lt;span style="color: #008000;"&gt;"LASTNAME"&lt;/span&gt; (elt contact 2)))
                                                (cdr (assoc &lt;span style="color: #008000;"&gt;"TAGS"&lt;/span&gt; (elt contact 2)))
                                                (cdr (assoc &lt;span style="color: #008000;"&gt;"EMAIL"&lt;/span&gt; (elt contact 2))))
                                               (cdr (assoc &lt;span style="color: #008000;"&gt;"EMAIL"&lt;/span&gt; (elt contact 2)))))
                                   &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;mu contacts&lt;/span&gt;
                                   (loop for contact in mu4e~contacts-for-completion
                                         collect (cons contact contact))))
                   &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;only action is to insert string at point.&lt;/span&gt;
                   (action . ((&lt;span style="color: #008000;"&gt;"insert"&lt;/span&gt; . (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (x)
                                            (insert
                                             (mapconcat
                                              'identity
                                              (helm-marked-candidates)
                                              &lt;span style="color: #008000;"&gt;","&lt;/span&gt;))))
                              (&lt;span style="color: #008000;"&gt;"open"&lt;/span&gt; . org-contacts-open-from-email)
                              (&lt;span style="color: #008000;"&gt;"tag"&lt;/span&gt;  . org-contacts-tag-selection)))))))

&lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;Finally, let us bind this to something probably convenient. I use c-c ] for&lt;/span&gt;
&lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;citations. Lets try that in compose mode.&lt;/span&gt;
(define-key mu4e-compose-mode-map &lt;span style="color: #008000;"&gt;"\C-c]"&lt;/span&gt; 'j-insert-emails)
&lt;/pre&gt;
&lt;/div&gt;
&lt;pre class="example"&gt;
j-insert-emails
&lt;/pre&gt;

&lt;p&gt;
Now, I have a sweet helm interface with nearly 13,000 email candidates (there is a decent amount of duplication in this list, and some garbage emails from spam, but helm is so fast, this does not bother me). I can pretty quickly narrow to any tagged set of emails from org-contacts with a search that looks like :phd: for example, or [^phd]:group: to get org-contacts tagged group, but not phd. I can narrow the selection on first name, lastname, parts of email addresses, tags in org-contacts, etc&amp;#x2026; I can open a contact, or tag contacts, even add new contacts to org-contacts. I have been using this for a few weeks, and so far I like it. Occasionally I find mu4e~contacts-for-completion is empty, and then I only get my org-contacts emails, but that seems to only happen when I first open emacs. Since Emacs is usually open for days at a time, this has not been an issue very often.
&lt;/p&gt;
&lt;p&gt;Copyright (C) 2015 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2015/03/14/A-helm-mu4e-contact-selector.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.10&lt;/p&gt;]]></content:encoded>
    </item>
    <item>
      <title>Better integration of org-mode and email</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2014/06/08/Better-integration-of-org-mode-and-email</link>
      <pubDate>Sun, 08 Jun 2014 20:57:53 EDT</pubDate>
      <category><![CDATA[email]]></category>
      <category><![CDATA[org-mode]]></category>
      <guid isPermaLink="false">yUG_aneLEa20f-MW4nCmuz3mT-Q=</guid>
      <description>Better integration of org-mode and email</description>
      <content:encoded><![CDATA[


&lt;p&gt;
I like to email org-mode headings and content to people. It would be nice to have some records of when a heading was sent, and to whom. We store this information in a heading. It is pretty easy to write a simple function that emails a selected region.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(defun email-region (start end)
  "Send region as the body of an email."
  (interactive "r")
  (let ((content (buffer-substring start end)))
    (compose-mail)
    (message-goto-body)
    (insert content)
    (message-goto-to)))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
that function is not glamorous, and you still have to fill in the email fields, and unless you use gnus and org-contacts, the only record keeping is through the email provider. 
&lt;/p&gt;

&lt;p&gt;
What I would like is to send a whole heading in an email. The headline should be the subject, and if there are TO, CC or BCC properties, those should be used. If there is &lt;i&gt;no TO&lt;/i&gt;, then I want to grab the TO from the email after you enter it and store it as a property. You should be able to set OTHER-HEADERS as a property (this is just for fun. There is no practical reason for this yet). After you send the email, it should record in the heading when it was sent.
&lt;/p&gt;

&lt;p&gt;
It turned out that is a relatively tall order. While it is easy to setup the email if you have everything in place, it is tricky to get the information on TO and the time sent &lt;i&gt;after&lt;/i&gt; the email is sent. Past lispers had a lot of ideas to make this possible, and a day of digging got me to the answer. You can specify some "action" functions that get called at various times, e.g. after sending, and a return action when the compose window is done. Unfortunately, I could not figure out any way to do things except to communicate through some global variables.
&lt;/p&gt;

&lt;p&gt;
So here is the code that lets me send org-headings, with the TO, CC, BCC properties, and that records when I sent the email after it is sent.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(defvar *email-heading-point* nil
  "global variable to store point in for returning")

(defvar *email-to-addresses* nil
  "global variable to store to address in email")

(defun email-heading-return ()
  "after returning from compose do this"
  (switch-to-buffer (marker-buffer  *email-heading-point*))
  (goto-char (marker-position  *email-heading-point*))
  (setq *email-heading-point* nil)
  (org-set-property "SENT-ON" (current-time-string))
  ;; reset this incase you added new ones
  (org-set-property "TO" *email-to-addresses*)
  )

(defun email-send-action ()
  "send action for compose-mail"
  (setq *email-to-addresses* (mail-fetch-field "To")))

(defun email-heading ()
  "Send the current org-mode heading as the body of an email, with headline as the subject.

use these properties
TO
OTHER-HEADERS is an alist specifying additional
header fields.  Elements look like (HEADER . VALUE) where both
HEADER and VALUE are strings.

save when it was sent as s SENT property. this is overwritten on
subsequent sends. could save them all in a logbook?
"
  (interactive)
  ; store location.
  (setq *email-heading-point* (set-marker (make-marker) (point)))
  (org-mark-subtree)
  (let ((content (buffer-substring (point) (mark)))
	(TO (org-entry-get (point) "TO" t))
	(CC (org-entry-get (point) "CC" t))
	(BCC (org-entry-get (point) "BCC" t))
	(SUBJECT (nth 4 (org-heading-components)))
	(OTHER-HEADERS (eval (org-entry-get (point) "OTHER-HEADERS")))
	(continue nil)
	(switch-function nil)
	(yank-action nil)
	(send-actions '((email-send-action . nil)))
	(return-action '(email-heading-return)))
    
    (compose-mail TO SUBJECT OTHER-HEADERS continue switch-function yank-action send-actions return-action)
    (message-goto-body)
    (insert content)
    (when CC
      (message-goto-cc)
      (insert CC))
    (when BCC
      (message-goto-bcc)
      (insert BCC))
    (if TO
	(message-goto-body)
      (message-goto-to))       
    ))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
This works pretty well for me. Since I normally use this to send tasks to people, it keeps the task organized where I want it, and I can embed an org-id in the email so if the person replies to it telling me the task is done, I can easily navigate to the task to mark it off. Pretty handy.
&lt;/p&gt;
&lt;p&gt;Copyright (C) 2014 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2014/06/08/Better-integration-of-org-mode-and-email.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.6&lt;/p&gt;]]></content:encoded>
    </item>
    <item>
      <title>Mail merge with python</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2013/04/16/Mail-merge-with-python</link>
      <pubDate>Tue, 16 Apr 2013 16:10:50 EDT</pubDate>
      <category><![CDATA[email]]></category>
      <category><![CDATA[programming]]></category>
      <guid isPermaLink="false">sCgugrC0d_UiINtcaOUhRVu9QBA=</guid>
      <description>Mail merge with python</description>
      <content:encoded><![CDATA[


&lt;p&gt;
Suppose you are organizing some event, and you have a mailing list of email addresses and people you need to send a mail to telling them what room they will be in. You would like to send a personalized email to each person, and you do not want to type each one by hand. Python can automate this for you. All you need is the mailing list in some kind of structured format, and then you can go through it line by line to create and send emails.
&lt;/p&gt;

&lt;p&gt;
We will use an org-table to store the data in.
&lt;/p&gt;

&lt;table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides" id="mail-list"&gt;
&lt;caption&gt;&lt;/caption&gt;

&lt;colgroup&gt;
&lt;col class="left"/&gt;

&lt;col class="left"/&gt;

&lt;col class="left"/&gt;

&lt;col class="right"/&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th scope="col" class="left"&gt;First name&lt;/th&gt;
&lt;th scope="col" class="left"&gt;Last name&lt;/th&gt;
&lt;th scope="col" class="left"&gt;email address&lt;/th&gt;
&lt;th scope="col" class="right"&gt;Room number&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="left"&gt;Jane&lt;/td&gt;
&lt;td class="left"&gt;Doe&lt;/td&gt;
&lt;td class="left"&gt;jane-doe@gmail.com&lt;/td&gt;
&lt;td class="right"&gt;1&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td class="left"&gt;John&lt;/td&gt;
&lt;td class="left"&gt;Doe&lt;/td&gt;
&lt;td class="left"&gt;john-doe@gmail.com&lt;/td&gt;
&lt;td class="right"&gt;2&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td class="left"&gt;Jimmy&lt;/td&gt;
&lt;td class="left"&gt;John&lt;/td&gt;
&lt;td class="left"&gt;jimmy-john@gmail.com&lt;/td&gt;
&lt;td class="right"&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;
We pass that table into an org-mode source block as a variable called data, which will be a list of lists, one for each row of the table. You could alternatively read these from an excel spreadsheet, a csv file, or some kind of python data structure. 
&lt;/p&gt;

&lt;p&gt;
We do not actually send the emails in this example. To do that you need to have access to a mail server, which could be on your own machine, or it could be a relay server you have access to.
&lt;/p&gt;

&lt;p&gt;
We create a string that is a template with some fields to be substituted, e.g. the firstname and room number in this case. Then we loop through each row of the table, and format the template with those values, and create an email message to the person. First we print each message to check that they are correct. 
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #ebbbff; font-weight: bold;"&gt;import&lt;/span&gt; smtplib
&lt;span style="color: #ebbbff; font-weight: bold;"&gt;from&lt;/span&gt; email.MIMEMultipart &lt;span style="color: #ebbbff; font-weight: bold;"&gt;import&lt;/span&gt; MIMEMultipart
&lt;span style="color: #ebbbff; font-weight: bold;"&gt;from&lt;/span&gt; email.MIMEText &lt;span style="color: #ebbbff; font-weight: bold;"&gt;import&lt;/span&gt; MIMEText
&lt;span style="color: #ebbbff; font-weight: bold;"&gt;from&lt;/span&gt; email.Utils &lt;span style="color: #ebbbff; font-weight: bold;"&gt;import&lt;/span&gt;  formatdate

template = &lt;span style="color: #d1f1a9;"&gt;'''&lt;/span&gt;
&lt;span style="color: #d1f1a9;"&gt;Dear {firstname:s},&lt;/span&gt;

&lt;span style="color: #d1f1a9;"&gt;I am pleased to inform you that your talk will be in room {roomnumber:d}.&lt;/span&gt;

&lt;span style="color: #d1f1a9;"&gt;Sincerely,&lt;/span&gt;
&lt;span style="color: #d1f1a9;"&gt;John&lt;/span&gt;
&lt;span style="color: #d1f1a9;"&gt;'''&lt;/span&gt;

&lt;span style="color: #ebbbff; font-weight: bold;"&gt;for&lt;/span&gt; firstname, lastname, emailaddress, roomnumber &lt;span style="color: #ebbbff; font-weight: bold;"&gt;in&lt;/span&gt; data:
    msg = MIMEMultipart()
    msg[&lt;span style="color: #d1f1a9;"&gt;'From'&lt;/span&gt;] = &lt;span style="color: #d1f1a9;"&gt;"youremail@gmail.com"&lt;/span&gt;
    msg[&lt;span style="color: #d1f1a9;"&gt;'To'&lt;/span&gt;] = emailaddress
    msg[&lt;span style="color: #d1f1a9;"&gt;'Date'&lt;/span&gt;] = formatdate(localtime=&lt;span style="color: #ebbbff; font-weight: bold;"&gt;True&lt;/span&gt;)

    msgtext = template.format(**&lt;span style="color: #ffc58f;"&gt;locals&lt;/span&gt;())
    &lt;span style="color: #ffc58f;"&gt;print&lt;/span&gt; msgtext

    msg.attach(MIMEText(msgtext))

    &lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;#&lt;/span&gt;&lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;# Uncomment these lines and fix &lt;/span&gt;
    &lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;#&lt;/span&gt;&lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;server = smtplib.SMTP('your.relay.server.edu')&lt;/span&gt;
    &lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;#&lt;/span&gt;&lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;server.sendmail('your_email@gmail.com', # from&lt;/span&gt;
    &lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;#                &lt;/span&gt;&lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;emailaddress,&lt;/span&gt;
    &lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;#                &lt;/span&gt;&lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;msg.as_string())&lt;/span&gt;
    &lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;#&lt;/span&gt;&lt;span style="color: #7285b7; font-weight: bold; font-style: italic;"&gt;server.quit()&lt;/span&gt;

    &lt;span style="color: #ffc58f;"&gt;print&lt;/span&gt; msg.as_string()
    &lt;span style="color: #ffc58f;"&gt;print&lt;/span&gt; &lt;span style="color: #d1f1a9;"&gt;'------------------------------------------------------------------'&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
Dear Jane,

I am pleased to inform you that your talk will be in room 1.

Sincerely,
John

Content-Type: multipart/mixed; boundary="===============1191311863=="
MIME-Version: 1.0
From: youremail@gmail.com
To: jane-doe@gmail.com
Date: Tue, 16 Apr 2013 16:10:23 -0400

--===============1191311863==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit


Dear Jane,

I am pleased to inform you that your talk will be in room 1.

Sincerely,
John

--===============1191311863==--
------------------------------------------------------------------

Dear John,

I am pleased to inform you that your talk will be in room 2.

Sincerely,
John

Content-Type: multipart/mixed; boundary="===============1713881863=="
MIME-Version: 1.0
From: youremail@gmail.com
To: john-doe@gmail.com
Date: Tue, 16 Apr 2013 16:10:23 -0400

--===============1713881863==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit


Dear John,

I am pleased to inform you that your talk will be in room 2.

Sincerely,
John

--===============1713881863==--
------------------------------------------------------------------

Dear Jimmy,

I am pleased to inform you that your talk will be in room 3.

Sincerely,
John

Content-Type: multipart/mixed; boundary="===============0696685580=="
MIME-Version: 1.0
From: youremail@gmail.com
To: jimmy-john@gmail.com
Date: Tue, 16 Apr 2013 16:10:23 -0400

--===============0696685580==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit


Dear Jimmy,

I am pleased to inform you that your talk will be in room 3.

Sincerely,
John

--===============0696685580==--
------------------------------------------------------------------
&lt;/pre&gt;
&lt;p&gt;Copyright (C) 2013 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2013/04/16/Mail-merge-with-python.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;]]></content:encoded>
    </item>
  </channel>
</rss>
