Wednesday, September 24, 2008

Emacs eMail

Not too long ago I decided to get all my mail via Gmail, and ignore the account I have with my internet service provider (ISP). Partly this is for the sake of simplicity. I don't have to check both accounts any more.

Partly it's also for security. I'm careful, but started getting a small amount of spam at my ISP account, and every now and then one of them would leak through security and into my inbox.

I started by forwarding all my mail from the ISP account to Gmail, and then over time have changed the email address registered with external businesses, so any newsletters or promotional announcements would go straight to Gmail. Google is better at managing spam than the average ISP, so this is a good idea from that standpoint as well.

I also have two accounts at Yahoo!, one of which serves as a primary backup for Gmail (anything coming to Gmail gets copied to Yahoo!), and the other of which I give out when I don't want any stray messages coming to my main mail accounts. Kind of goofy, but it works for me.

For some reason or other...oh, yes, it's coming back now...I have Emacs set up so C-c m will take me to the buffer list...and sometimes I hit C-x m instead, and end up inside an Emacs *mail* buffer.

Ok, anyway, I started thinking about sending mail from Emacs.

I recently configured Mozilla Thunderbird to send mail via my Gmail account, and to automatically download any new messages from Gmail's inbox whenever I fire it up. Working with Thunderbird is a lot nicer than working through a browser, and it lets me have a local copy of everything, just in case Gmail isn't working some day. In that case I could always send mail through Yahoo! or my ISP, and if my Gmail account gets deleted or suspended for some reason known only to Google, which has basically no customer service, I will still have all my email, stored locally, on my own hard drive. And I can delete older messages and confidential ones from Gmail and not worry about privacy.

So last night I decided to see if I could set up Emacs to send mail (send only -- not read -- Thunderbird is for that).

I found a good blog post called "Configuring Emacs for Gmail's SMTP" at "This sentence is false", owned by Denis Bueno. But I couldn't get things working last night.

On another blog called "Arg and gah and ap and pa" I found "Sending mail through gmail Using Emacs", which I ignored until this morning. I tried it and it worked. I also used a tip from the first blog to fancy things up a bit.

The process, in brief:
  1. Install starttls
  2. Modify ~/.emacs
  3. Add ~/.authinfo

I installed starttls on my Kubuntu system via the Synaptic Package Manager. Use whatever is appropriate for you. I am new to Linux so I don't know the best way to do anything.

Here is what I ended up adding to my ~/.emacs file:
;; Sending email via Gmail. Info is from:
;; http://argandgahandapandpa.wordpress.com/2008/04/27/sending-mail-through-gmail-using-emacs/
;; supplemented by
;; http://obfuscatedcode.wordpress.com/2007/04/26/configuring-emacs-for-gmails-smtp/
;;
;; To see output in a buffer named "trace of SMTP...", uncomment the following two lines for debugging.
;;(setq smtpmail-debug-info t)
;;(setq smtpmail-debug-verb t)
;;
;; The following sends email via smtp. If problems, the smtp server may need restarting.
;; Email address and password are held in "~/.authinfo"
;;
(setq send-mail-function 'smtpmail-send-it)
(setq smtpmail-smtp-server "smtp.gmail.com")
(setq smtpmail-smtp-service 25)
(setq smtpmail-auth-credentials (expand-file-name "~/.authinfo"))
(setq smtpmail-starttls-credentials '(("smtp.gmail.com" 25 nil nil)))

Here is what I have in my ~/.authinfo file:
machine smtp.gmail.com login [my-id]@gmail.com password [my-password]

To use, replace "[my-id]" and "[my-password]" with your Gmail user id and password (no quotes or brackets of course).

See the "Configuring Emacs for Gmail's SMTP" post for security issues and why to use the .authinfo file.

I did have one problem when Emacs reported that the SMTP server was not running. I'm not sure about that. I used C-x m to open a new *mail* buffer, typed in a test message, and usec C-c C-c to send, and got the Linux version of the hourglass. After a long while I managed to abort the hung process somehow and got a message in the minibuffer at the bottom of the Emacs window about SMTP not being active.

I uncommented the two SMTP debugging lines in .emacs, opened a new Emacs session and tried again, successfully.

You can find more info by checking the Emacs manual (at the menu bar, go to Help -> Read the Emacs Manual (C-h r) ).

Now why in the hell would I do this? Nothing like getting to the point. The point is that I often want to remember something, to look up later or to add to a list of URLs or a list of interesting sites or programs, and sending a quick note to my Gmail account is a way of saving a thought for later. Saving in a way that I can get access from any of my three computers (Gmail functions as my network).

Might work.

References.

Configuring Emacs for Gmail's SMTP
gnutls (GNU TLS encryption library)
Sending mail through gmail Using Emacs
starttls (Simple wrapper program for STARTTLS protocol)

0 comments :

Post a Comment