Sending Email from Emacs

Since Emacs is my main workhorse it comes handy to send plain text email straight from an Emacs buffer. Like for example this blog post directly from Emacs to the Rforge blog.

Emacs needs some configuration to do this, which I found on’s Emacs Speaks SMTP:

First you need a helper application which enables Emacs to use a crypted connection to an IMAP server like e.g. starttls:

sudo aptitude install starttls

Then include the following into your ~/.emacs file to setup the outgoing mail server (SMTP):

;; Emacs Speaks SMTP ( using the default mail agent ;; If you use the default mail user agent.
(setq send-mail-function 'smtpmail-send-it)
;; Send mail using SMTP via gmail.
(setq smtpmail-smtp-server "")
;; Send mail using SMTP on the mail submission port 587.
(setq smtpmail-smtp-service 587)
;; Authenticate using this username and password against (setq smtpmail-auth-credentials
'(("" 587 "captain.cheese" nil)))
;; Use STARTTLS against the server.
(setq smtpmail-starttls-credentials
'(("" 587 "captain.cheese" nil)))

when you are not using gmail, you have to find out which SMTP server and port your provider uses and captain.cheese has to be changed to your user account. Note that nil can be changed to your passphrase, which I do not recommend since the .emacs file is plain text so it is possible to read your passphrase…

The standard Emacs keys to open an empty email formular is Control-x m, which I found to awkward, so I changed it to Hyper-c (this requires having CapsLock redefined as “Hyper”-key, which is another story and highly recommendable): (DefGlobKey "H-c" 'compose-mail)
(DefGlobKey "H-M-c" 'mail-send-and-exit)

Now H-c opens an email and after writing it H-M-c sends it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s