VM

[gnu.emacs.vm.info] Re: sending html mail using VM

Bug #207383 reported by Robert Widhopf-Fenk
8
Affects Status Importance Assigned to Milestone
VM
Fix Released
Wishlist
Uday Reddy

Bug Description

 affects viewmail

From: Eric Schulte <email address hidden>
Organization: schulte
Newsgroups: gnu.emacs.vm.info
Date: Thu, 10 Jan 2008 18:36:28 -0800
Subject: Re: sending html mail using VM

Eric Schulte <email address hidden> writes:

> <email address hidden> writes:
>
>> Eric Schulte <email address hidden> writes:
>>
>>> Like it or not most of the people I email with (especially at work),
>>> use mail readers that work best with HTML formatted mail.
>>>
>>> I use org-mode for most of my note taking, and there are many times
>>> when I would like to send formatted mail with tables, bold text
>>> etc... to these people. Their mail readers don't use fixed width
>>> fonts, so my tables display as garbage. However I can export my
>>> org-mode notes to very nice html documents.
>>>
>>> Is there a way for me to
>>>
>>> 1. compose mail in org-mode
>>> 2. on sending convert the mail to html
>>> 3. send the mail as a mime-type text/html message using VM
>>>
>>> I have just tried to send some simple html mail using vm just by
>>> adding a "Content-Type:" header to the top of the mail, but that
>>> wasn't sufficient.
>>
>> Two headers are required, Mime-Version and Content-Type, e.g.
>>
>> ,----
>> | MIME-Version: 1.0
>> | Content-Type: text/html; charset="iso-8859-1"
>> `----
>>
>> This should be sufficient.
>>
>> The even the charset may be dropped.
>>
>> From an org-mode buffer use something like ...
>>
>> (defun org-mode-2-vm-mail ()
>> (let ((html-buffer (get-buffer-create "*html*")))
>> (org-export-as-html nil nil nil html-buffer nil)
>> (vm-mail)
>> (goto-char (point-min))
>> (insert "MIME-Version: 1.0\n")
>> (insert "Content-Type: text/html")
>> (search-forward mail-header-separator)
>> (delete-region (point) (point-max))
>> (insert "\n")
>> (insert-buffer-substring html-buffer)
>> (kill-buffer html-buffer)
>> (message "Add the headers...")))
>>
>> It could be better, e.g. org-mode just for the body and normal
>> vm-mail-mode on top, but I am not sure how this should interact.
>>
>> Robert.
>
> Thanks for the code!
>
> Actually there is already a way to have org-mode active while
> composing text emails (info "(org)orgstruct-mode"), intended for
> people who like the way org indents lists, etc... This intercepts the
> "\C-c\C-c" command and uses it for org things or passes it to the
> major mode depending on where in the buffer you lie. I'm working on
> changing the behavior of orgstruct-mode so that if you use "\C-c\C-c"
> with a prefix command in a mail buffer, it will send the body as html.
> Hopefully your code will complete what I've got so far.
>
> for kicks I'll paste in what I have now, although currently all it
> does is intercept prefix'd "\C-c\C-c" commands.
>
> Thanks again
> Eric
>
>
> (defun orgstruct-hijacker-command-11 (arg)
> "In Structure, run `org-ctrl-c-ctrl-c'. Outside of Structure
> check for a prefix argument and if buffer name contains `mail',
> and run orgstruct-send-as-html, or run the binding of
> `\C-c\C-c'."
> (interactive "p")
> (if (org-context-p (quote headline) (quote item))
> (org-run-like-in-org-mode (quote org-ctrl-c-ctrl-c))
> (if (orgstruct-send-as-html-should-i-p arg)
> (orgstruct-send-as-html arg)
> (let (orgstruct-mode)
> (call-interactively
> (key-binding "\C-c\C-c"))))))
>
> (defun orgstruct-send-as-html-should-i-p (arg)
> (if (and arg (> arg 1) (string-match "mail" (buffer-name (current-buffer))))
> t))
>
> (defun orgstruct-send-as-html (arg)
> "Export the body of the mail message as html using
> `org-export-region-as-html', then attach to the messge, change the
> mail's mime type appropriately, then send"
> ;; use org-export-region-as-html to export body to temporary buffer
> ;; attach to the mail using vm-mime-attach-buffer
> ;; send the mail
> )
>
> --
> schulte

It seems to be working with these functions

if you use orgstruct-mode with or without orgtble-mode load the
following functions, then you can send convert and send html mail with
"\C-u\C-c\C-c"

Cheers,
Eric

(defun orgstruct-hijacker-command-11 (arg)
  "In Structure, run `org-ctrl-c-ctrl-c'. Outside of Structure
check for a prefix argument and if buffer name contains `mail',
and run orgstruct-send-as-html, or run the binding of
`\C-c\C-c'."
  (interactive "p")
  (if (org-context-p (quote headline) (quote item))
      (org-run-like-in-org-mode (quote org-ctrl-c-ctrl-c))
    (if (orgstruct-send-as-html-should-i-p arg)
        (orgstruct-send-as-html)
      (let (orgstruct-mode)
        (call-interactively
         (key-binding "\C-c\C-c"))))))

(defun orgstruct-send-as-html-should-i-p (arg)
  "lets be pretty sure we have a prefix argument and are actually
in a mail buffer"
  (goto-char (point-min))
  (if (and arg
           (> arg 1)
           (string-match "mail" (buffer-name (current-buffer)))
           (search-forward mail-header-separator))
      t))

(defun orgstruct-send-as-html ()
  "Export the body of the mail message to html using
`org-export-as-html' then send the results as a text/html
Content-Type message"
  ;; adjust mime type
  (goto-char (point-min))
  (insert "MIME-Version: 1.0\n")
  (insert "Content-Type: text/html\n")
  (search-forward mail-header-separator)
  (let* ((mail-text-point (point))
         (mail-buffer (current-buffer))
         ;; have to write the file because org needs a path to export
         (tmp-file (make-temp-name (expand-file-name "org-html-mail" "/tmp")))
         (html
          (progn
            (write-file tmp-file)
            ;; convert to html
            (org-export-region-as-html mail-text-point (point-max) t 'string))))
    (switch-to-buffer mail-buffer)
    (set-visited-file-name nil)
    (delete-file tmp-file)
    ;; replace text with html
    (goto-char mail-text-point)
    (delete-region (point) (point-max))
    (insert "\n")
    (insert html)
    ;; send the mail
    (let (orgstruct-mode)
      (call-interactively
       (key-binding "\C-c\C-c")))))

Uday Reddy (reddyuday)
Changed in vm:
importance: Undecided → Wishlist
Uday Reddy (reddyuday)
Changed in viewmail:
importance: Undecided → Wishlist
Revision history for this message
Uday Reddy (reddyuday) wrote :

File org-html-mail.el from Eric Schulte added to the contrib directory.

Changed in vm:
status: New → Fix Committed
assignee: nobody → Uday Reddy (reddyuday)
milestone: none → 8.2.0-devo
status: Fix Committed → Fix Released
Uday Reddy (reddyuday)
Changed in vm:
milestone: 8.2.0-devo → 8.1.90a
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.