Gmail from Emacs

I’ve meant to set up email from emacs for a while, but only recently got around to setting it up. I use GMail, so I’d wanted email sent from emacs to appear as being sent from my gmail account. To do this, you must install the ’starttls’ program. On Ubuntu, this can be done with ’sudo apt-get install starttls’. Once that is done, put the following in your .emacs file:

(setq send-mail-function 'smtpmail-send-it
      message-send-mail-function 'smtpmail-send-it
      smtpmail-starttls-credentials
      '(("smtp.gmail.com" 587 nil nil))
      smtpmail-auth-credentials
      (expand-file-name "~/.authinfo")
      smtpmail-default-smtp-server "smtp.gmail.com"
      smtpmail-smtp-server "smtp.gmail.com"
      smtpmail-smtp-service 587
      smtpmail-debug-info t)
(require 'smtpmail)

You will also need to create a ~/.authoinfo file with the following format:

machine smtp.gmail.com login username@gmail.com password secret

Once you add these customizations, you will be able to use ‘C-x m’ in order to create an email and send it to people. However, this does not allow you to read and reply to email from emacs. Unfortunately, I haven’t found a great solution for that yet; I tried using GNUs a while ago and didn’t like it, but if you want to try it the information on how to do so is located on the emacs-wiki. The other option that I sometimes use is to have a w3m buffer open and pointing to Gmail, but w3m isn’t as good as I would like and so this isn’t the best experience either. Let me Please let me now if you know of a better way to handle mail from emacs.

Tags:

13 Responses to “Gmail from Emacs”

  1. Ed Singleton says:

    I’ve pretty much been having the same thought process, although without the actual bothering to put it into practice. From what I’ve read so far WanderLust seems to be very well regarded, though I haven’t tried it. Maybe this will be the impetus for me to actually sit down tonight and try it out.

  2. Andrzej Skiba says:

    I’ve used wanderlust for my gmail account for a while. Googling “emacs wanderlust gmail” will give you plenty of info on setting it up :)

  3. Qbi's Weblog says:

    E-Mails von GMail mit Gnus lesen…

    Wenn ich nach meinen E-Mail-Kontakten wird Google Mail recht häufig benutzt. Selbst Universitäten setzen das schon anstelle eines richtigen Mailservers ein. Ich habe mir vor langer Zeit mal einen Zugang geklickt und lasse da zumeist diverse Mailingli…

  4. sajith says:

    I have used Gnus with Gmail IMAP with some happiness. I have heard of people using offlineimap + gnus + gmail with much more happiness.

  5. [...] This post was Twitted by cycojesus [...]

  6. Seth says:

    How did you set up w3m for gmail? I keep getting directed to some page that w3m can’t download.

  7. Ryan says:

    I recently switched to offlineimap + wanderlust + gmail and am very happy with it so far. I was using gnus before and didn’t quite get along with it.

  8. éric says:

    I recommend Wanderlust as well, generally but also specifically for access to google’s mail.

  9. Mathias Dahl says:

    This was very helpful, thanks!

    Now I have a small script that lets me send mail using Emacs and Gmail from the command line. First a small .el file:

    ;; gmail-emacs.el

    (setq send-mail-function ’smtpmail-send-it
    message-send-mail-function ’smtpmail-send-it
    smtpmail-starttls-credentials ‘((”smtp.gmail.com” 587 nil nil))
    smtpmail-auth-credentials (expand-file-name “~/.authinfo”)
    smtpmail-default-smtp-server “smtp.gmail.com”
    smtpmail-smtp-server “smtp.gmail.com”
    smtpmail-smtp-service 587 smtpmail-debug-info t)

    (require ’smtpmail)

    (add-hook ‘mail-mode-hook ‘mail-abbrevs-setup)

    (compose-mail)

    Next the small script `gmailemacs’:

    #!/bin/bash
    emacs -Q -nw -l ~/doc/src/el/gmail-emacs.el

    Of course, if I am inside emacs already I just do C-x m directly.

    I also exported to CSV my most used contacts from Gmail and made them into mail aliases and put them in my .mailrc, like so:

    alias SHORTNAME LONGEMAILADRESS

    The hook addition above makes sure the aliases expand when I type space so that I can see the expanded address before sending (it will be expanded when sent anyway). Using C-c C-a I can now also lookup any such alias and get it expanded at point.

    /Mathias

  10. Mathias Dahl says:

    Please note that in my code snippets above, the single and double quotes has been converted to those yucky counterparts. Before you try it, please replace those with simple single and double quotes.

  11. Chris Newton says:

    I’ll throw in with the wanderlust comments. I’ve recently tried to get back to email in emacs and found that wanderlust + offlineimap + gmail works well. It even works if you add in davmail + exchange (if you’re unlucky like me and have to use exchange for work). Wanderlust can do ldap contact expanding well too. Unfortunately offlineimap doesn’t play nice with davmail.

  12. I really enjoyed reading this post, thanks for sharing. I hope that you keep updating the blog.

  13. Sebastian Willert says:

    Minor addendum (as this is still very high in the google search results for “emacs gmail”):
    You need to do `sudo apt-get install gnutls-bin` on modern Ubuntu dists instead of `sudo apt-get install starttls` and you can set you default mail adress (the “From:” part) via “(setq user-mail-address “XXX@gmail.com”)”.

    Cheers

Leave a Reply