emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* html-email in org-mode
@ 2016-10-29 18:37 John Kitchin
  2016-10-30 14:34 ` Eric Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: John Kitchin @ 2016-10-29 18:37 UTC (permalink / raw)
  To: Emacs-orgmode@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 8578 bytes --]

* DONE Sending html emails from org-mode with org-mime
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. I am going to send this post to the orgmode mailing list as an html mail to make sure it works. It should show as a text mail in mu4e, and an html mail in a browser.


As I played around with it though, I came across some limitations:

1. 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 [[id:14317E51-C65E-48DD-9B52-B94D6B458E8F][here]].
2. I found it useful to modify the org-mime commands to leave point in the To: field when composing emails from org-buffers.
3. 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 [[id:D44F059D-180C-41C5-BA0A-873723E0DDFB][(here)]].

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.

First, you need to require this library.

#+BEGIN_SRC emacs-lisp
(require 'org-mime)
#+END_SRC

You can send a whole org buffer in html like with this command: [[elisp:org-mime-org-buffer-htmlize]]. Not all of the internal links work for me (at least in gmail).

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.

#+BEGIN_SRC emacs-lisp
(defun org-mime-org-buffer-htmlize ()
  "Create an email buffer containing the current org-mode file
  exported to html and encoded in both html and in org formats as
  mime alternatives."
  (interactive)
  (org-mime-send-buffer 'html)
  (message-goto-to))
#+END_SRC

** From an org-headline in an org-file
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.:

#+BEGIN_EXAMPLE
   :PROPERTIES:
   :MAIL_FMT: html
   :END:
#+END_EXAMPLE

Note the following properties can also be set to modify the composed email.
#+BEGIN_SRC emacs-lisp
	   (subject (or (funcall mp "MAIL_SUBJECT") (nth 4 (org-heading-components))))
	   (to (funcall mp "MAIL_TO"))
	   (cc (funcall mp "MAIL_CC"))
	   (bcc (funcall mp "MAIL_BCC"))
#+END_SRC

Then, send it with [[elisp:org-mime-subtree]]

Here I modify this function to leave me in the To: field.

#+BEGIN_SRC emacs-lisp
(defun org-mime-subtree ()
  "Create an email buffer containing the current org-mode subtree
  exported to a org format or to the format specified by the
  MAIL_FMT property of the subtree."
  (interactive)
  (org-mime-send-subtree
   (or (org-entry-get nil "MAIL_FMT" org-mime-use-property-inheritance) 'org))
  (message-goto-to))
#+END_SRC

Here are some sample elements to see if they convert to html reasonably.

*** Markup
*bold*

_underlined_

/italics/

+strikethrough+

~code~

Subscripts: H_{2}O
Superscripts: H^{+}
An entity: To \infty and beyond

*** Equations
\(x^2\)

\[x^4\]

$e^x$

*** Tables

#+CAPTION: A table for you.
| x | y |
| 1 | 2 |

*** Lists

A nested list.
- one
  - Subentry under one.
- two


A definition list:

- def1 :: first definition

A checklist:
- [ ] A checkbox


Here is a numbered list:

1. number 1
2. number 2

*** Code block

#+BEGIN_SRC python
import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 10)
x = np.cos(t) * np.exp(-t)
y = np.sin(t) * np.exp(-t)

plt.plot(x, y)
plt.savefig('spiral.png')
#+END_SRC

#+CAPTION: A spiral
[[file:./spiral.png]]

*** An image from somewhere other than this directory
#+CAPTION: A gold particle
[[file:./images/Au-icosahedron-3.png]]

*** Citations with org-ref

#+NAME: table-1
| a | b | c |

See Table [[ref:table-1]].

[[#Dominik201408][Dominik201408]]

* Bibliography
**  - 
  :PROPERTIES:
     :CUSTOM_ID: Dominik201408
   :=TYPE=: book
   :=KEY=: Dominik201408
   :TITLE: {The Org Mode 8 Reference Manual - Organize your life with GNU
                  Emacs}
   :AUTHOR: {Carsten Dominik}
   :PUBLISHER: {Samurai Media Limited}
   :YEAR: 2014
   :MONTH: 8
   :ISBN: 9789881327703
   :URL: {http://amazon.com/o/ASIN/9881327709/}
   :PRICE: {\$19.99}
   :TOTALPAGES: 286
   :TIMESTAMP: {2015.02.03}
   :KEYWORDS: {org-mode}
  :END:

** In a mail message
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. 

#+BEGIN_SRC emacs-lisp
(defun mu4e-compose-org-mail ()
 (interactive)
 (mu4e-compose-new)
 (org-mu4e-compose-org-mode))
#+END_SRC

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.

#+BEGIN_SRC emacs-lisp
(defun htmlize-and-send ()
  "When in an org-mu4e-compose-org-mode message, htmlize and send it."
  (interactive)
  (when (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)
#+END_SRC

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.

#+BEGIN_SRC emacs-lisp
(defun compose-html-org ()
  (interactive)
  (compose-mail)
  (message-goto-body)
  (setq *compose-html-org* t)
  (org-mode))

(defun org-htmlize-and-send ()
  "When in an org-mu4e-compose-org-mode message, htmlize and send it."
  (interactive)
  
  (when *compose-html-org*
    (setq *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)
#+END_SRC

** Equations and file attachments do not seem to work out of the box
\(e^{i\pi} - 1 = 0\)

Out of the box, org-mime does not seem to attach file links to emails or make images for equations..

[[file:html-email.org]] 

Here is an adaptation of org-mime-compose that does that for html messages.

#+BEGIN_SRC emacs-lisp
(defun org-mime-compose (body fmt file &optional to subject headers)
  (require 'message)
  (let ((bhook
	 (lambda (body fmt)
	   (let ((hook (intern (concat "org-mime-pre-"
				       (symbol-name fmt)
				       "-hook"))))
	     (if (> (eval `(length ,hook)) 0)
		 (with-temp-buffer
		   (insert body)
		   (goto-char (point-min))
		   (eval `(run-hooks ',hook))
		   (buffer-string))
	       body))))
	(fmt (if (symbolp fmt) fmt (intern fmt)))
	(files (org-element-map (org-element-parse-buffer) 'link
		 (lambda (link)
		   (when (string= (org-element-property :type link) "file")
		     (file-truename (org-element-property :path link)))))))
    (compose-mail to subject headers nil)
    (message-goto-body)
    (cond
     ((eq fmt 'org)
      (require 'ox-org)
      (insert (org-export-string-as
	       (org-babel-trim (funcall bhook body 'org)) 'org t)))
     ((eq fmt 'ascii)
      (require 'ox-ascii)
      (insert (org-export-string-as
	       (concat "#+Title:\n" (funcall bhook body 'ascii)) 'ascii t)))
     ((or (eq fmt 'html) (eq fmt 'html-ascii))
      (require 'ox-ascii)
      (require 'ox-org)
      (let* ((org-link-file-path-type 'absolute)
	     ;; we probably don't want to export a huge style file
	     (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 (if (eq fmt 'html) 'org 'ascii)))
		  (if (eq fmt 'html) 'org 'ascii) t)
		 html)
		(mapconcat 'identity images "\n")))))
    (mapc #'mml-attach-file files)))
#+END_SRC

** Summary
This makes it pretty nice to send rich-formatted html text to people.

[-- Attachment #1.2: Type: text/html, Size: 17906 bytes --]

[-- Attachment #2: latex11551eXz_71dd900d7f17a20875918a89a10eb146fccdd464.png --]
[-- Type: image/png, Size: 369 bytes --]

[-- Attachment #3: Au-icosahedron-3.png --]
[-- Type: image/png, Size: 30407 bytes --]

[-- Attachment #4: spiral.png --]
[-- Type: image/png, Size: 20044 bytes --]

[-- Attachment #5: latex11551EDn_c53faf490456a009247152f9614e65ac64628f0c.png --]
[-- Type: image/png, Size: 231 bytes --]

[-- Attachment #6: latex11551qua_398423584a3c15c2862f1218805c1a0068adb398.png --]
[-- Type: image/png, Size: 248 bytes --]

[-- Attachment #7: latex11551QaO_e39ccbca7983ec6a4ba1d3dcc1d807f16d4dfc22.png --]
[-- Type: image/png, Size: 255 bytes --]

[-- Attachment #8: spiral.png --]
[-- Type: image/png, Size: 20044 bytes --]

[-- Attachment #9: Au-icosahedron-3.png --]
[-- Type: image/png, Size: 30407 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #10: html-email.org --]
[-- Type: text/x-org, Size: 9034 bytes --]

* DONE Sending html emails from org-mode with org-mime
  CLOSED: [2016-10-29 Sat 14:33]
  :PROPERTIES:
  :categories: email,orgmode
  :ID:       181982DB-1843-4C3C-8E75-687CFF86A470
  :date:     2016/10/29 14:33:16
  :updated:  2016/10/29 14:33:16
  :END:

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. I am going to send this post to the orgmode mailing list as an html mail to make sure it works. It should show as a text mail in mu4e, and an html mail in a browser.


As I played around with it though, I came across some limitations:

1. 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 [[id:14317E51-C65E-48DD-9B52-B94D6B458E8F][here]].
2. I found it useful to modify the org-mime commands to leave point in the To: field when composing emails from org-buffers.
3. 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 [[id:D44F059D-180C-41C5-BA0A-873723E0DDFB][(here)]].

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.

First, you need to require this library.

#+BEGIN_SRC emacs-lisp
(require 'org-mime)
#+END_SRC

#+RESULTS:
: org-mime

You can send a whole org buffer in html like with this command: elisp:org-mime-org-buffer-htmlize. Not all of the internal links work for me (at least in gmail).

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.

#+BEGIN_SRC emacs-lisp
(defun org-mime-org-buffer-htmlize ()
  "Create an email buffer containing the current org-mode file
  exported to html and encoded in both html and in org formats as
  mime alternatives."
  (interactive)
  (org-mime-send-buffer 'html)
  (message-goto-to))
#+END_SRC

#+RESULTS:
: org-mime-org-buffer-htmlize

** From an org-headline in an org-file
   :PROPERTIES:
   :MAIL_FMT: html
   :END:

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.:

#+BEGIN_EXAMPLE
   :PROPERTIES:
   :MAIL_FMT: html
   :END:
#+END_EXAMPLE

Note the following properties can also be set to modify the composed email.
#+BEGIN_SRC emacs-lisp
	   (subject (or (funcall mp "MAIL_SUBJECT") (nth 4 (org-heading-components))))
	   (to (funcall mp "MAIL_TO"))
	   (cc (funcall mp "MAIL_CC"))
	   (bcc (funcall mp "MAIL_BCC"))
#+END_SRC

Then, send it with elisp:org-mime-subtree

Here I modify this function to leave me in the To: field.

#+BEGIN_SRC emacs-lisp
(defun org-mime-subtree ()
  "Create an email buffer containing the current org-mode subtree
  exported to a org format or to the format specified by the
  MAIL_FMT property of the subtree."
  (interactive)
  (org-mime-send-subtree
   (or (org-entry-get nil "MAIL_FMT" org-mime-use-property-inheritance) 'org))
  (message-goto-to))
#+END_SRC

#+RESULTS:
: org-mime-subtree

Here are some sample elements to see if they convert to html reasonably.

*** Markup
*bold*

_underlined_

/italics/

+strikethrough+

~code~

Subscripts: H_{2}O
Superscripts: H^{+}
An entity: To \infty and beyond

*** Equations
    :PROPERTIES:
    :MAIL_FMT: html
    :END:

\(x^2\)

\[x^4\]

$e^x$

*** Tables

#+caption: A table for you.
| x | y |
| 1 | 2 |

*** Lists

A nested list.
- one
  - Subentry under one.
- two


A definition list:

- def1 :: first definition

A checklist:
- [ ] A checkbox


Here is a numbered list:

1. number 1
2. number 2

*** Code block

 #+BEGIN_SRC python :results output org drawer
import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 10)
x = np.cos(t) * np.exp(-t)
y = np.sin(t) * np.exp(-t)

plt.plot(x, y)
plt.savefig('spiral.png')
 #+END_SRC

 #+caption: A spiral
 [[./spiral.png]]

*** An image from somewhere other than this directory
    :PROPERTIES:
    :MAIL_FMT: html
    :END:

 #+caption: A gold particle
 [[./images/Au-icosahedron-3.png]]

*** Citations with org-ref

#+name: table-1
| a | b | c |

See Table ref:table-1.

cite:Dominik201408

bibliography:../../../Dropbox/bibliography/references.bib

** In a mail message
   :PROPERTIES:
   :ID:       D44F059D-180C-41C5-BA0A-873723E0DDFB
   :END:

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. 

#+BEGIN_SRC emacs-lisp
(defun mu4e-compose-org-mail ()
 (interactive)
 (mu4e-compose-new)
 (org-mu4e-compose-org-mode))
#+END_SRC

#+RESULTS:
: mu4e-compose-org-mail

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.

#+BEGIN_SRC emacs-lisp
(defun htmlize-and-send ()
  "When in an org-mu4e-compose-org-mode message, htmlize and send it."
  (interactive)
  (when (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)
#+END_SRC

#+RESULTS:
| org-babel-hash-at-point | org-babel-execute-safely-maybe | htmlize-and-send |

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.

#+BEGIN_SRC emacs-lisp
(defun compose-html-org ()
  (interactive)
  (compose-mail)
  (message-goto-body)
  (setq *compose-html-org* t)
  (org-mode))

(defun org-htmlize-and-send ()
  "When in an org-mu4e-compose-org-mode message, htmlize and send it."
  (interactive)
  
  (when *compose-html-org*
    (setq *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)
#+END_SRC

#+RESULTS:
| org-babel-hash-at-point | org-babel-execute-safely-maybe | htmlize-and-send | org-htmlize-and-send |

** Equations and file attachments do not seem to work out of the box
   :PROPERTIES:
   :ID:       14317E51-C65E-48DD-9B52-B94D6B458E8F
   :MAIL_FMT: html
   :END:

\(e^{i\pi} - 1 = 0\)

Out of the box, org-mime does not seem to attach file links to emails or make images for equations..

file:html-email.org 

Here is an adaptation of org-mime-compose that does that for html messages.

#+BEGIN_SRC emacs-lisp
(defun org-mime-compose (body fmt file &optional to subject headers)
  (require 'message)
  (let ((bhook
	 (lambda (body fmt)
	   (let ((hook (intern (concat "org-mime-pre-"
				       (symbol-name fmt)
				       "-hook"))))
	     (if (> (eval `(length ,hook)) 0)
		 (with-temp-buffer
		   (insert body)
		   (goto-char (point-min))
		   (eval `(run-hooks ',hook))
		   (buffer-string))
	       body))))
	(fmt (if (symbolp fmt) fmt (intern fmt)))
	(files (org-element-map (org-element-parse-buffer) 'link
		 (lambda (link)
		   (when (string= (org-element-property :type link) "file")
		     (file-truename (org-element-property :path link)))))))
    (compose-mail to subject headers nil)
    (message-goto-body)
    (cond
     ((eq fmt 'org)
      (require 'ox-org)
      (insert (org-export-string-as
	       (org-babel-trim (funcall bhook body 'org)) 'org t)))
     ((eq fmt 'ascii)
      (require 'ox-ascii)
      (insert (org-export-string-as
	       (concat "#+Title:\n" (funcall bhook body 'ascii)) 'ascii t)))
     ((or (eq fmt 'html) (eq fmt 'html-ascii))
      (require 'ox-ascii)
      (require 'ox-org)
      (let* ((org-link-file-path-type 'absolute)
	     ;; we probably don't want to export a huge style file
	     (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 (if (eq fmt 'html) 'org 'ascii)))
		  (if (eq fmt 'html) 'org 'ascii) t)
		 html)
		(mapconcat 'identity images "\n")))))
    (mapc #'mml-attach-file files)))
#+END_SRC

#+RESULTS:
: org-mime-compose

** Summary
This makes it pretty nice to send rich-formatted html text to people.

[-- Attachment #11: Type: text/plain, Size: 190 bytes --]


-- 
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: html-email in org-mode
  2016-10-29 18:37 html-email in org-mode John Kitchin
@ 2016-10-30 14:34 ` Eric Brown
  2016-10-30 15:09   ` Marcin Borkowski
  2016-10-30 21:45   ` John Kitchin
  2016-11-01 19:25 ` Alan Schmitt
  2016-11-07 15:37 ` Joseph Vidal-Rosset
  2 siblings, 2 replies; 11+ messages in thread
From: Eric Brown @ 2016-10-30 14:34 UTC (permalink / raw)
  To: John Kitchin; +Cc: Emacs-orgmode@gnu.org

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> 1.1.3 Tables
>
>  Table 1: A table for you.  
>   x  y    
>   1  2    
>

Hi John,

I haven't (yet) found the email thread that you had alluded to, but I
think this post is awesome.  Works well for me!

One suggestion/thought:

I would like to do is force monospace font in these messages, since the
recipients I typically send to will have variable width fonts, and
tables and the like tend to get messed up.

How might this be done?

Best regards,
Eric

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: html-email in org-mode
  2016-10-30 14:34 ` Eric Brown
@ 2016-10-30 15:09   ` Marcin Borkowski
  2016-10-30 21:45   ` John Kitchin
  1 sibling, 0 replies; 11+ messages in thread
From: Marcin Borkowski @ 2016-10-30 15:09 UTC (permalink / raw)
  To: Eric Brown; +Cc: Emacs-orgmode@gnu.org, John Kitchin


On 2016-10-30, at 15:34, Eric Brown <brown@fastmail.com> wrote:

> One suggestion/thought:
>
> I would like to do is force monospace font in these messages, since the
> recipients I typically send to will have variable width fonts, and
> tables and the like tend to get messed up.

+20! (that is, +2432902008176640000)

I'm not very interested in sending HTML emails, but this would be
AWESOME.  I sometimes send ASCII-art-ish tables (like Org-mode ones, or
Ledger reports) by email, and opening them in variable-width font is
rather messy indeed.

TIA,

-- 
Marcin Borkowski

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: html-email in org-mode
@ 2016-10-30 15:44 tbanelwebmin
  0 siblings, 0 replies; 11+ messages in thread
From: tbanelwebmin @ 2016-10-30 15:44 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 171 bytes --]


* Awesome
This is awesome!

* Simple
I followed your instructions, and in 2 minutes I was able to send a
/1st/ mail from Org Mode

* Thanks
Thanks John for showing that.

[-- Attachment #2: Type: text/html, Size: 982 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: html-email in org-mode
  2016-10-30 14:34 ` Eric Brown
  2016-10-30 15:09   ` Marcin Borkowski
@ 2016-10-30 21:45   ` John Kitchin
  2016-11-01 11:58     ` Eric Brown
  1 sibling, 1 reply; 11+ messages in thread
From: John Kitchin @ 2016-10-30 21:45 UTC (permalink / raw)
  To: Eric Brown; +Cc: Emacs-orgmode@gnu.org

Do you mean monospace in the whole html message, e.g. something like Courier?

Or just in a table? I do not think you can control the font in plain
text emails.

You can set the font in the td elements of a table like this (I used
cursive because it was easy to see.

#+BEGIN_SRC emacs-lisp
(defun italicize-table (data backend info)
  (with-temp-buffer
    (insert data)
    (goto-char (point-min))
    (while (re-search-forward "<td" nil t)
      (replace-match "<td style=\"font-family:cursive;\""))
    (message"got %s" (buffer-string))
    (buffer-string)))


(add-to-list 'org-export-filter-table-functions 'italicize-table)
#+END_SRC

After you run that, the tables in html have italicized/cursive elements
in them. And probably all other exports to html too ;)

Eric Brown writes:

> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> 1.1.3 Tables
>>
>>  Table 1: A table for you.  
>>   x  y    
>>   1  2    
>>
>
> Hi John,
>
> I haven't (yet) found the email thread that you had alluded to, but I
> think this post is awesome.  Works well for me!
>
> One suggestion/thought:
>
> I would like to do is force monospace font in these messages, since the
> recipients I typically send to will have variable width fonts, and
> tables and the like tend to get messed up.
>
> How might this be done?
>
> Best regards,
> Eric


-- 
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: html-email in org-mode
  2016-10-30 21:45   ` John Kitchin
@ 2016-11-01 11:58     ` Eric Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Eric Brown @ 2016-11-01 11:58 UTC (permalink / raw)
  To: John Kitchin; +Cc: Emacs-orgmode@gnu.org

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> Do you mean monospace in the whole html message, e.g. something like Courier?
>
> Or just in a table? I do not think you can control the font in plain
> text emails.
>
> You can set the font in the td elements of a table like this (I used
> cursive because it was easy to see.
>
> #+BEGIN_SRC emacs-lisp
> (defun italicize-table (data backend info)
>   (with-temp-buffer
>     (insert data)
>     (goto-char (point-min))
>     (while (re-search-forward "<td" nil t)
>       (replace-match "<td style=\"font-family:cursive;\""))
>     (message"got %s" (buffer-string))
>     (buffer-string)))
>
>
> (add-to-list 'org-export-filter-table-functions 'italicize-table)
> #+END_SRC
>
> After you run that, the tables in html have italicized/cursive elements
> in them. And probably all other exports to html too ;)
>

Thanks, this is extremely useful, as well.  In retrospect, I think my
question may be a bit moot, as the HTML formatting would probably allow
tables to remain aligned regardless of length of any one cell.

My comment was motivated by other usage where I wish that I could simply
wrap an entire simple text, whitespace-formatted email message,
e.g. generated from org export to a plain text buffer, with a Monospace
directive so that webmail users could appreciate what I see with Sans
Mono.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: html-email in org-mode
  2016-10-29 18:37 html-email in org-mode John Kitchin
  2016-10-30 14:34 ` Eric Brown
@ 2016-11-01 19:25 ` Alan Schmitt
  2016-11-05  0:13   ` Matt Price
  2016-11-07 15:37 ` Joseph Vidal-Rosset
  2 siblings, 1 reply; 11+ messages in thread
From: Alan Schmitt @ 2016-11-01 19:25 UTC (permalink / raw)
  To: John Kitchin; +Cc: Emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 708 bytes --]

On 2016-10-29 15:37, John Kitchin <jkitchin@andrew.cmu.edu> writes:

> 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. I am going to send this post to the orgmode mailing
> list as an html mail to make sure it works. It should show as a text
> mail in mu4e, and an html mail in a browser.

It's looking great in gnus, by the way. Equations and images are
displayed very nicely. Thanks!

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂, Mauna Loa Obs. 2016-09: 401.03, 2015-09: 397.63

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 454 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: html-email in org-mode
  2016-11-01 19:25 ` Alan Schmitt
@ 2016-11-05  0:13   ` Matt Price
  2016-11-07  2:55     ` John Kitchin
  0 siblings, 1 reply; 11+ messages in thread
From: Matt Price @ 2016-11-05  0:13 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: Emacs-orgmode@gnu.org, John Kitchin


[-- Attachment #1.1: Type: text/plain, Size: 1013 bytes --]

John, I'm moving this over to this thread because I think my issues with
htmlize-and-send might not be because of any errors in my setup.

When I use John's htmlize-and-send, or any similar function, to attempt to
send an html email from org-mode, I get an error from message-send:
"Message already sent via mail; resend?" Attmepting to resend fails
silently, and the message is neither sent nor saved to archives.
Interestingly, the first time I try this in a new emacs session, I get no
error message ( though the message doesn't actually get sent). This makes
me wonder if there's something wrong with the way
mu4e/message/htmlize-and-send is keeping track of messages.

I've attached the minimal mail-test.el that I use to start emacs; I'm using
a pretty recent emacs-git with the latest org-mode git, on Arch Linux, with
offlineimap and nullmailer (which has a sendmail clone). If anyone out
there has a moment to look at my config and tell me if they see anything
wrong... I'd aprreciate it. Th
anks,

Matt

[-- Attachment #1.2: Type: text/html, Size: 1247 bytes --]

[-- Attachment #2: mail-test.el --]
[-- Type: text/x-emacs-lisp, Size: 10587 bytes --]

;; example configuration for mu4e
(add-to-list 'load-path "/home/matt/src/mu/mu4e/" )
(add-to-list 'load-path "/home/matt/src/org-mode/lisp/" )
(add-to-list 'load-path "/home/matt/src/org-mode/contrib/lisp/" )

;; make sure mu4e is in your load-path
(require 'mu4e)
(require 'org)
(require 'org-mime)


;; Only needed if your maildir is _not_ ~/Maildir
;; Must be a real dir, not a symlink
(setq mu4e-maildir "/home/matt/UofTMail/")

;; these must start with a "/", and must exist
;; (i.e.. /home/user/Maildir/sent must exist)
;; you use e.g. 'mu mkdir' to make the Maildirs if they don't
;; already exist

;; below are the defaults; if they do not exist yet, mu4e offers to
;; create them. they can also functions; see their docstrings.
(setq mu4e-sent-folder   "/Sent")
(setq mu4e-drafts-folder "/Drafts")
(setq mu4e-trash-folder  "/Trash")
(setq mu4e-refile-folder  "/Archives")

;; smtp mail setting; these are the same that `gnus' uses.
(setq
 ;;message-send-mail-function   'smtpmail-send-it
 smtpmail-default-smtp-server "smtp.utoronto.ca"
 smtpmail-smtp-server         "smtp.utoronto.ca"
 smtpmail-local-domain        "utoronto.ca")


;; use msmtp instead of sendmail!
;; actually we're using nullmailer now. Both are great, but nullmailer send is subjetively instantaneous
(setq message-send-mail-function 'message-send-mail-with-sendmail)
;; instead of sending directly with msmtp, sned with the enqueue script
;;(setq sendmail-program "/usr/local/bin/msmtp-enqueue.sh")
(setq sendmail-program "/usr/bin/sendmail")
;;(setq sendmail-program "/usr/bin/msmtp")

      ;;; This line allows you to store a quick link to the relevant email in a TODO item.
      ;;; thank you, Pragmatic Emacs: http://pragmaticemacs.com/emacs/master-your-inbox-with-mu4e-and-org-mode/
;;store org-mode links to messages
(require 'org-mu4e)
;;store link to message if in header view, not to header query
(setq org-mu4e-link-query-in-headers-mode nil)



;; the maildirs you use frequently; access them with 'j' ('jump')
(setq   mu4e-maildir-shortcuts
        '(("/inbox"       . ?i)
          ("/Archives"     . ?a)
          ("/Sent"        . ?s)))

;; a  list of user's e-mail addresses
(setq mu4e-user-mail-address-list '("matt.price@utoronto.ca" "moptop99@gmail.com"))

;; when you want to use some external command for text->html
;; conversion, e.g. the 'html2text' program
;; (setq mu4e-html2text-command "html2text")
;; commenting out for testing
;; (require 'mu4e-contrib)
;; (setq mu4e-html2text-command 'mu4e-shr2text)
;; (add-hook 'mu4e-view-mode-hook
;;           (lambda()
;;             ;; try to emulate some of the eww key-bindings
;;             (local-set-key (kbd "<tab>") 'shr-next-link)
;;             (local-set-key (kbd "<backtab>") 'shr-previous-link)))


;; the headers to show in the headers list -- a pair of a field
;; and its width, with `nil' meaning 'unlimited'
;; (better only use that for the last field.

;; commenting out for testing
;; These are the defaults:
;; (setq mu4e-headers-fields
;;       '( (:human-date          .  25)    ;; alternatively, use :human-date
;;          (:flags         .   6)
;;          (:mailing-list         .   10)
;;          ;;(:attachments   .   6)
;;          (:from-or-to          .  22)
;;          (:subject       .  nil))) ;; alternatively, use :thread-subject

;; program to get mail; alternatives are 'fetchmail', 'getmail'
;; isync or your own shellscript. called when 'U' is pressed in
;; main view.

;; If you get your mail without an explicit command,
;; use "true" for the command (this is the default)
(setq mu4e-get-mail-command "offlineimap")

;; general emacs mail settings; used when composing e-mail
;; the non-mu4e-* stuff is inherited from emacs/message-mode
(setq mu4e-reply-to-address "matt.price@utoronto.ca"
      user-mail-address "matt.price@utoronto.ca"
      user-full-name  "Matt Price")
(setq mu4e-compose-signature
      "")

;; smtp mail setting
;; I don't think this is being used by nullmailer at all, so probably irrelefant for me.
;; (setq

;;  ;; if you need offline mode, set these -- and create the queue dir
;;  ;; with 'mu mkdir', i.e.. mu mkdir /home/user/Maildir/queue
;;  smtpmail-queue-mail  nil
;;  smtpmail-queue-dir  "/home/matt/UofTMail/queue/cur")

;; don't keep message buffers around
;; commenting out in case this is an issue.  
;;(setq message-kill-buffer-on-exit t)

;; commenting out for troubleshooting.
;; split horizontally, which is how I like it
;; actually, switch to vertical (which is bizarrely called horizontal)
;; can't seem to get it to switch, so we'll see how it goes.
;; (setq ;; mu4e-split-view 'horizontal
;;  mu4e-headers-visible-lines 15
;;  mu4e-headers-visible-columns 80)

;; view images inline
;; enable inline images
;; (setq mu4e-view-show-images t)
;; ;; use imagemagick, if available
;; (when (fboundp 'imagemagick-register-types)
;;   (imagemagick-register-types))

;; extract attachments
;; consider doing some sorting, e.g.: http://www.djcbsoftware.nl/code/mu/mu4e/Attachments.html#Attachments
(setq mu4e-attachment-dir  "~/Downloads")
(setq mu4e-attachment-dir
      (lambda (fname mtype)
        (cond
         ;; jpgs go to ~/Pictures/FromEmails
         ((and fname (string-match "\\.jpg$" fname))  "~/Pictures/FromEmails")
         ;; ... other cases  ...
         (t "~/Downloads")))) ;; everything else
;; 

;; This is a rewrite if mu4e-main from [[https://github.com/zmalltalker/dot-emacs/blob/master/contrib/mu4e/mu4e-main.el]]

;; (eval-after-load 'mu4e 
;;   '(define-key mu4e-main-mode-map "m" 'mu4e-main-toggle-mail-sending-mode))
;; (eval-after-load 'mu4e 
;;   '(define-key mu4e-main-mode-map "f" 'smtpmail-send-queued-mail))


;; comment out all my new keybindings
;; (defun my-mu4e-main-mode-config ()
;;   "For use in `mu4e-main-mode-hook'."
;;   (local-set-key (kbd "m") 'mu4e-main-toggle-mail-sending-mode) ; add a key
;;   (local-set-key (kbd "f") 'smtpmail-send-queued-mail) ; add a key
;;   ;;(local-set-key (kbd "C-c C-p") nil) ; example of remove a key
;;   ;; more here
;;   )

;; (defun my-mu4e-headers-mode-config ()
;;   "For use in 'mu4e-view-mode-hook'."
;;   (local-set-key (kbd "a") 'mu4e-headers-mark-for-refile) ;; remap from "r"
;;   (local-set-key (kbd "r") 'mu4e-compose-reply) ;; add new keymapping, along with "R"
;;   (local-set-key (kbd "C-c C-v") 'mu4e-headers-action) ;; rebind from a
;;   )

;; (defun my-mu4e-view-mode-config ()
;;   "For use in 'mu4e-view-mode-hook'."
;;   (local-set-key (kbd "a") 'mu4e-view-mark-for-refile) ;; remap from "r"
;;   (local-set-key (kbd "r") 'mu4e-compose-reply) ;; add new keymapping, along with "R"
;;   (local-set-key (kbd "C-c C-v") 'mu4e-view-action) ;; rebind from a
;;   (visual-line-mode)
;;   )



;; (define-key mu4e-headers-mode-map (kbd "C-c c") 'org-mu4e-store-and-capture)
;; (define-key mu4e-view-mode-map    (kbd "C-c c") 'org-mu4e-store-and-capture)
;; (define-key mu4e-headers-mode-map "x" #'my-mu4e-mark-execute-all-no-confirm)  ;; turn off execution ocnfirmation

;; ;; add to hook
;; (add-hook 'mu4e-main-mode-hook 'my-mu4e-main-mode-config)
;; (add-hook 'mu4e-headers-mode-hook 'my-mu4e-headers-mode-config)
;; (add-hook 'mu4e-view-mode-hook 'my-mu4e-view-mode-config)


;; configure view actions
(add-to-list 'mu4e-view-actions
             '("ViewInBrowser" . mu4e-action-view-in-browser) t)

      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Interactive functions

;; (defun my-mu4e-mark-execute-all-no-confirm ()
;;   "Execute all marks without confirmation."
;;   (interactive)
;;   (mu4e-mark-execute-all 'no-confirm))

;; this seemed essential at first but now I'm not using the mstpmail queue
;; (defun mu4e-main-toggle-mail-sending-mode ()
;;   "Toggle sending mail mode, either queued or direct."
;;   (interactive)
;;   (unless (file-directory-p smtpmail-queue-dir)
;;     (mu4e-error "`smtpmail-queue-dir' does not exist"))
;;   (setq smtpmail-queue-mail (not smtpmail-queue-mail))
;;   (message
;;    (concat "Outgoing mail will now be "
;;            (if smtpmail-queue-mail "queued" "sent directly")))
;;   (mu4e~main-view))



;; use flowed text in ocmpose mode os your emails don't look awful
;; tip submitted by mu4e user cpbotha (from manual, appendix)
;; unfortunatley this seems to interfere with John Kitchin;sstuff. Disabling for now,
;; will submit report
;; (add-hook 'mu4e-compose-mode-hook
;;           (defun cpb-compose-setup ()
;;             "Outgoing mails get format=flowed."
;;             (use-hard-newlines t 'guess)))

;; this might be overlapping with the below...
;; in fact it almost certainly is
;; (add-hook 'mu4e-compose-mode-hook
;;           (defun do-compose-stuff ()
;;   "My settings for message composition."
;;             (org-mu4e-compose-org-mode)))


;;  make use of org-mode in ocmposition mode, and show html versions by defaul...
;; I think there might be a conflict with org-mu4e-convert-to-html t
;; Since I seem to have discovered the problem elsewhere, I'll consider changing this back
;; soon. 
;; (setq ;; org-mu4e-convert-to-html t
;;  mu4e-view-prefer-html  t)


;; john kitchin's trick to check for attachments:
;; http://kitchingroup.cheme.cmu.edu/blog/category/email/



(defun org-mime-org-buffer-htmlize ()
  "Create an email buffer containing the current org-mode file
  exported to html and encoded in both html and in org formats as
  mime alternatives."
  (interactive)
  (org-mime-send-buffer 'html)
  (message-goto-to))

(defun org-mime-subtree ()
  "Create an email buffer containing the current org-mode subtree
  exported to a org format or to the format specified by the
  MAIL_FMT property of the subtree."
  (interactive)
  (org-mime-send-subtree
   (or (org-entry-get nil "MAIL_FMT" org-mime-use-property-inheritance) 'org))
  (message-goto-to))

(defun mu4e-compose-org-mail ()
  (interactive)
  (mu4e-compose-new)
  (org-mu4e-compose-org-mode))

(defun htmlize-and-send ()
  "When in an org-mu4e-compose-org-mode message, htmlize and send it."
  (interactive)
  ;;(message "hello")
  (when (member 'org~mu4e-mime-switch-headers-or-body post-command-hook)
    (goto-char (point-min))
    (org-mime-htmlize)
    (message-send-and-exit)))

(add-hook 'org-ctrl-c-ctrl-c-hook 'htmlize-and-send t)

(defun mwp-send-from-org ()
  "when in org-mu4e-compose-org-mode message, just send it b/c htmlize has already been hooke in"
  (interactive)
  (when (member 'org~mu4e-mime-switch-headers-or-body post-command-hook)
    (goto-char (point-min))
    (message-send-and-exit)))

;;(add-hook 'org-ctrl-c-ctrl-c-hook 'mwp-send-from-org t)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: html-email in org-mode
  2016-11-01 16:10 (no subject) John Kitchin
@ 2016-11-06  0:27 ` Eric Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Eric Brown @ 2016-11-06  0:27 UTC (permalink / raw)
  To: John Kitchin; +Cc: Emacs-orgmode@gnu.org, John Kitchin

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> htmlize-mail.org
>
>
> * Send org files by html email so they look like org files.
>   :PROPERTIES:
>   :MAIL_FMT: html
>   :END:
>
> We might not always want a full export of an org heading to html for sending an email. Eric Brown would like to just send something that looks like what he sees in org-mode. There is another way to get html from emacs: htmlize! Here is an example. Eric: if this is what you mean, see my modified org-mime.el at https://github.com/jkitchin/scimax/blob/master/org-mime.el. 
>
> The command to send a subtree is: elisp:org-mime-subtree-htmlize
>
>
> #+BEGIN_EXAMPLE
> My comment was motivated by other usage where I wish that I could simply
> wrap an entire simple text, whitespace-formatted email message,
> e.g. generated from org export to a plain text buffer, with a Monospace
> directive so that webmail users could appreciate what I see with Sans
> Mono.
> #+END_EXAMPLE
>
> | a | b | c |
> | 4 | 5 | 6 |
>
> An equation 
> \(e^{i\pi} + 1 = 0\)
>
>
> A figure: 
>
> #+name: fig-particle
> #+attr_org: :width 30%
> ./images/Au-icosahedron-3.png
>
>
> A code block:
> #+BEGIN_SRC python :results output org drawer
> for i in range(5):
>     print(i)
> #+END_SRC
>
> ** A subtree
>
> An orgmode reference: cite:Dominik201408. A figure reference: ref:fig-particle.


Thanks John. This is very helpful!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: html-email in org-mode
  2016-11-05  0:13   ` Matt Price
@ 2016-11-07  2:55     ` John Kitchin
  0 siblings, 0 replies; 11+ messages in thread
From: John Kitchin @ 2016-11-07  2:55 UTC (permalink / raw)
  To: Matt Price; +Cc: Alan Schmitt, Emacs-orgmode@gnu.org

I can not reproduce your error.

I feel like when I saw that error it was from calling a send command
while in org-mode, and not in message-mode. 

Matt Price writes:

> John, I'm moving this over to this thread because I think my issues with
> htmlize-and-send might not be because of any errors in my setup.
>
> When I use John's htmlize-and-send, or any similar function, to attempt to
> send an html email from org-mode, I get an error from message-send:
> "Message already sent via mail; resend?" Attmepting to resend fails
> silently, and the message is neither sent nor saved to archives.
> Interestingly, the first time I try this in a new emacs session, I get no
> error message ( though the message doesn't actually get sent). This makes
> me wonder if there's something wrong with the way
> mu4e/message/htmlize-and-send is keeping track of messages.
>
> I've attached the minimal mail-test.el that I use to start emacs; I'm using
> a pretty recent emacs-git with the latest org-mode git, on Arch Linux, with
> offlineimap and nullmailer (which has a sendmail clone). If anyone out
> there has a moment to look at my config and tell me if they see anything
> wrong... I'd aprreciate it. Th
> anks,
>
> Matt


-- 
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: html-email in org-mode
  2016-10-29 18:37 html-email in org-mode John Kitchin
  2016-10-30 14:34 ` Eric Brown
  2016-11-01 19:25 ` Alan Schmitt
@ 2016-11-07 15:37 ` Joseph Vidal-Rosset
  2 siblings, 0 replies; 11+ messages in thread
From: Joseph Vidal-Rosset @ 2016-11-07 15:37 UTC (permalink / raw)
  To: John Kitchin; +Cc: Emacs-orgmode@gnu.org

Many thanks John for this email and also for your very useful videos.

As I told you, I use sometimes gnus + org-mode to make roughly the
same things that  you make with m4ue. Your message  appears correctly in
two formats  in gnus: multipart/mixed  and text/html. In a  browser used
with gmail its html is perfect.

I confess  that I  do not  succeed to use  only gnus  for my  email, but
mainly    when    it    is     more    convenient    for    professional
reasons. Unfortunately, I have not still succeed to use gnorb, because I
do not  understand clearly how  it works.  But even without  gnorb, gnus
works well in harmony with gmail in IMAP.

Maybe some  people in this  list could  share their experiences  with an
emacs email  client + org-mode  and help to  make the better  choice, if
possible?

Best wishes,

Jo. 

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-11-07 15:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-29 18:37 html-email in org-mode John Kitchin
2016-10-30 14:34 ` Eric Brown
2016-10-30 15:09   ` Marcin Borkowski
2016-10-30 21:45   ` John Kitchin
2016-11-01 11:58     ` Eric Brown
2016-11-01 19:25 ` Alan Schmitt
2016-11-05  0:13   ` Matt Price
2016-11-07  2:55     ` John Kitchin
2016-11-07 15:37 ` Joseph Vidal-Rosset
  -- strict thread matches above, loose matches on Subject: below --
2016-10-30 15:44 tbanelwebmin
2016-11-01 16:10 (no subject) John Kitchin
2016-11-06  0:27 ` html-email in org-mode Eric Brown

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).