Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is a question originally posed on https://answers.launchpad.net/vm/+question/108267 on 2010-04-26.

It asks how one should configure Emacs mail sending packages on MS Windows for use with secure SMTP server such as gmail, which require TLS and STARTTLS. The original question is copied below.

  • I installed Cygwins gnutls.

  • In .emacs wrote:

    (setq send-mail-function 'smtpmail-send-it
      message-send-mail-function 'smtpmail-send-it
      '(("smtp.gmail.com" 587 nil nil))
      (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 'starttls)
    (setq starttls-use-gnutls t)
    (setq smtpmail-debug-info t)
    (setq smtpmail-debug-verb t)
    (require 'smtpmail)
  • I created "~/.authinfo" file with gmail credentials.

  • I removed starttls.elc, so the compiled version won't be loaded by emacs.

  • I replaced (signal-process (process-id process) 'SIGALRM) to

    (call-process "g:\\www\\cygwin\\bin\\kill.exe" nil nil nil
              "-ALRM" (format "%d" (process-id process)))

I used the description from: http://obfuscatedcode.wordpress.com/2007/04/26/configuring-emacs-for-gmails-smtp/

  • When I try to send the mail, it says in minibuffer: "Sending failed SMTP error"

In the debug buffer I get an error:

'Process SMTP exited abnormally with code 53'

that doesn't tell me anything useful.

share|improve this question

migrated from stackoverflow.com Sep 18 '12 at 19:22

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

up vote 3 down vote accepted

The following is advice that led to the question of the moment. The advice was unearthed by Uday Reddy and can be found at http://article.gmane.org/gmane.emacs.windows/3250. It is dated 8/7/2006.

The problem boils down to the fact that the command

(signal-process (process-id process) 'SIGALRM)

does not work with Win32 Emacs, even with Cygwin also installed.  But one can mimic that with:

(call-process "c:\\cygwin\\bin\\kill.exe" nil nil nil
                                     "-ALRM" (format "%d" (process-id 

According to the documention of gnutsl-cli (e.g. http://www.gnu.org/software/gnutls/manual/html_node/gnutls_002dcli-Invocation.html#gnutls_002dcli-Invocation):

starttls option (-s)

This is the "connect, establish a plain session and start tls." option. The TLS session will be initiated when EOF or a SIGALRM is received.

Bug #7789, discussed at newsgroup gnu.emacs.bug, reports this signaling deficiency in MS Windows (aka Woe32).

I also followed the advice to make this change (in function "starttls-negotiate-gnutls" in file "starttls.el") but I was still unsuccessful in sending a test email via the server smtp.gmail.com:587.

I determined that a fix is to change the line in function "smtpmail-via-smtp" in file "smtpmail.el" that reads:

(setq process (smtpmail-open-stream process-buffer host port))


(let ((coding-system-for-read 'raw-text-unix))
  (setq process (smtpmail-open-stream process-buffer host port)))

This insures that no coding conversion takes place when the server response is inserted into "process-buffer". In particular, it ensures that the CRLF character pair at the end of the 220 greeting from the server does not get altered.

With this one additional change I was successful in sending a test email via smtp.gmail.com:587.

My Emacs version information is "GNU Emacs 23.3.1 (i386-mingw-nt5.1.2600) of 2011-03-10 on 3249CTO".

I later found that my fix is covered by the discussion at http://comments.gmane.org/gmane.emacs.devel/140976. The general title of that discussion is "Changing the default for `send-mail-function'" (it began on 6/26/11). The changes discussed there--that make the fix--made it into Emacs 24, but are not present in Emacs 23.3 or 23.4.

share|improve this answer
While investigating how to send email from Emacs via smtp.gmail.com another solution was to use "stunnel" from Cygwin in the same manner that VM uses it to connect to e.g. a POP server. I modified function "smtpmail-via-smtp" in "smtpmail.el" so that it used "stunnel" in this manner and was successful in sending test mails via "smtp.gmail.com:465". For reference, see [stackoverflow.com/q/9694912/1264870] (Reading email from Emacs VM using a secure server (Gmail) [closed]). –  Alan Wehmann Mar 15 '12 at 17:44
add comment

It looks like Emacs 24 (currently on pre-release) has made several improvements and things are a lot simpler. First of all, the smtpmail library can now do plain SSL. There is no need to STARTTLS. And, gmail SMTP supports SSL on port 465.

So, here are the settings required:

(setq smtpmail-stream-type 'ssl)
(setq smtpmail-smtp-server "smtp.gmail.com")
(setq smtpmail-smtp-service 465)

The authentication credentials (login and password) should go into a file ~/.authinfo or ~/.authinfo.gpg. (They cannot be put in Emacs variables any more.) There, you need to include a line of the form

machine smtp.gmail.com login ..... password ..... port 465

That is all there is to it.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.