Mi Marcin,
I am using a different approach. It works more or less well.
Less, becaue I can only write one html mail without being disturbed by the question if I like to resend the mail.
There somehow seems to be a problem with indexing of the html mails.
But take a look a the code:
;; Org-mode integration
(require 'org-mime)
(setq org-mime-library 'mml)
(defun org-mime-htmlize (&optional arg)
"Export a portion of an email body composed using `mml-mode' to
html using `org-mode'. If called with an active region only
export that region, otherwise export the entire body."
(interactive "P")
(require 'ox-org)
(require 'ox-html)
(let* ((region-p (org-region-active-p))
(html-start (or (and region-p (region-beginning))
(save-excursion
(goto-char (point-min))
(search-forward mail-header-separator)
(+ (point) 1))))
(html-end (or (and region-p (region-end))
;; TODO: should catch signature...
(point-max)))
(raw-body (concat org-mime-default-header
(buffer-substring html-start html-end)))
(tmp-file (make-temp-name (expand-file-name
"mail" temporary-file-directory)))
(body (org-export-string-as raw-body 'org t))
;; because we probably don't want to export a huge style file
(org-export-htmlize-output-type 'inline-css)
;; makes the replies with ">"s look nicer
(org-export-preserve-breaks org-mime-preserve-breaks)
;; dvipng for inline latex because MathJax doesn't work in mail
(org-html-with-latex 'dvipng)
;; to hold attachments for inline html images
(html-and-images
(org-mime-replace-images
(org-export-string-as raw-body 'html t) tmp-file))
(html-images (unless arg (cdr html-and-images)))
(html (org-mime-apply-html-hook
(if arg
(format org-mime-fixedwith-wrap body)
(car html-and-images)))))
(delete-region html-start html-end)
(save-excursion
(goto-char html-start)
(insert (org-mime-multipart
body html (mapconcat 'identity html-images "\n"))))))
(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 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)
(switch-to-buffer " *mu4e-main*")))
(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 'dvisvgm)
(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)))
(add-hook 'org-ctrl-c-ctrl-c-hook 'htmlize-and-send t)
(define-key mu4e-compose-mode-map (kbd "C-c o") 'org-mu4e-compose-org-mode)
(global-set-key (kbd "C-c o") 'org-mu4e-compose-org-mode)
If you press C-c o in a message buffer in the message area. You start to compose an html mail using org-mode with all its features.
Unfortunately. I don't know where I found this function. I did not save the source. If anyone knows the author, please mention him.
I found a similar solution on
http://kitchingroup.cheme.cmu.edu/blog/2016/10/29/Sending-html-emails-from-org-mode-with-org-mime/ But this is not exactly the same implementation.
If you find out how to modify the code, so that the sent emails are indexed in the correct way. Then let me know. This would be the perfect way to handle org-mode integration.
With regards,
Nils