Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to configure emacs to send mail through an SMTP server, but so far, I've not been successful. Here's the output I'm getting:

220 __SMTP.SERVER__ ESMTP Sendmail 8.14.4+UW11.03/8.14.4+UW13.09; Wed, 15 Jan 2014 13:16:39 -0800
250-__SMTP.SERVER__ Hello __LOCAL.DOMAIN__ [__IP.ADDRESS__], pleased to meet you
250-SIZE 60000000
250 HELP
250 2.0.0 Verbose mode
250 2.1.0 <__USER@DOMAIN__>... Sender ok
530 5.7.1 Relaying denied. Proper authentication required.
smtpmail-send-it: Sending failed; SMTP protocol error

Relevant init.el is setup thus:

(setq send-mail-function 'smtpmail-send-it)
(setq smtpmail-smtp-server "__SMTP.SERVER__")
(setq smtpmail-smtp-service 587)
(setq smtpmail-stream-type 'ssl)
(setq smtpmail-debug-info t)
(setq smtpmail-debug-verb t)

There also exists a .authinfo file, which reads:

machine __SMTP.SERVER__ port 587 login __USER__ password *

Any thoughts on what I've missed or done incorrectly?


@techie007 I've talked with the server admin, and he's told me that the server is supposed to allow relaying after authentication; now I'm wondering if I've set up my authentication incorrectly. I know that the server uses TLS encryption, and I know that I've configured smtpmail-stream-type 'ssl instead of 'tls, but the emacs documentation led me to believe that 'ssl is to be used for both SSL and TLS connections ( Is this wrong?

Additionally, the SMTP server does indeed work with other clients; it's just this particular connection that I'm having trouble making.


A retooling of init.el now reads:

 (setq message-send-mail-function 'smtpmail-send-it
      smtpmail-starttls-credentials '(("__SMPT.SERVER__" 587 nil nil))
      smtpmail-auth-credentials '(("__SMTP.SERVER" 587 "__USER__" nil))
      smtpmail-default-smtp-server "__SMTP_SERVER__"
      smtpmail-smtp-server "__SMTP.SERVER__"
      smtpmail-smtp-service 587
      smtpmail-local-domain "__LOCAL.DOMAIN__")

which has removed the need for a .authinfo file. Full log including an attempt to send mail:

Loading 00debian-vars...done
Loading /etc/emacs/site-start.d/50autoconf.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading debian-ispell...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...done
Loading debian-ispell...done
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...done
Loading /etc/emacs/site-start.d/50psvn.el (source)...done
Loading /etc/emacs23/site-start.d/50vm-init.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
goto-history-element: Beginning of history; no preceding item
Loading /home/__USER__/.xemacs/init.el (source)...done
Loading /home/__USER__/.xemacs/custom.el (source)...done
/usr/bin/mail is not an executable. Setting mail-interactive to t.
Adding vm-rfaddons-option `check-recipients'.
Adding vm-rfaddons-option `check-for-empty-subject'.
Adding vm-rfaddons-option `encode-headers'.
VM-RFADDONS: VM is now infected.
ispell.el is already loaded
Added to /home/__USER__/vm-folders/SentMail
sendmail-send-it: Sending...failed with exit value 1


I've managed to make some progress! On initial startup of Emacs, I start VM with C-x m, and if I try to send a message, I'm met with the failure in the first output - smtpmail-send-it: Sending failed; SMTP protocol error. However, if I C-x C-f ~/.emacs to open the file and then enter M-x eval-buffer, I can then go back into VM and send a message perfectly fine. The .emacs configuration is thus:

(setq message-send-mail-function 'smtpmail-send-it
      send-mail-function 'smtpmail-send-it
      smtpmail-default-smtp-server "__SMTP.SERVER__"
      smtpmail-smtp-server "__SMTP.SERVER__"
      smtpmail-smtp-service 587
      smtpmail-stream-type 'ssl
      smtpmail-auth-credentials '(("__SMTP.SERVER__" 587 "__USER__" "__PASSWORD__"))

Does anybody know how I can eliminate the need to evaluate .emacs at the start of every Emacs session?


It works! For closure's sake, let me post my final working configuration here.

(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/vm/")
(require 'vm-autoloads)
(load "/usr/local/share/emacs/site-lisp/vm/vm-reply")
(setq message-send-mail-function 'smtpmail-send-it
      send-mail-function 'smtpmail-send-it
      user-mail-address "__USER.MAIL.ADDRESS__"
      smtpmail-default-smtp-server "__SMTP.SERVER__" 
      smtpmail-smtp-server "__SMTP.SERVER__"
      smtpmail-smtp-service 587
      smtpmail-stream-type 'ssl
      smtpmail-smtp-user "__USER__"
      smtpmail-starttls-credentials '(("__SMTP.SERVER__" 587 "__USER__" nil)))
      starttls-use-gnutls t 
      starttls-gnutls-program "gnutls-cli"
      starttls-extra-arguments nil

Putting in the 'load-path and 'vm-autoloads seemed to help with a couple of "function definition is void" errors, and the manual load of vm-reply is a workaround to a bug found in VM 8.2.0b, consisting of a missing autoload; otherwise, it resulted in a void definition of vm-select-recipient-from-sender. I also went back to using the .authinfo file to authenticate once I realized that it was conflicting with the smtpmail-auth-credentials variable; smtpmail-smtp-user is used in conjunction with .authinfo as per netawater's suggestion. user-mail-address solved any remaining authentication errors I had.

Thanks, everyone, for all your help and suggestions!

share|improve this question
Yeah, you're trying to Relay through a mail server that disallows Relaying. "5.7.1 Relaying denied." Just being authenticated may not be enough, depending on how the server is set up. Have you spoken to the mail server admins yet regarding their chosen rules? Can you send mail from this computer/network using that account and mail server via a standard mail client? – Ƭᴇcʜιᴇ007 Jan 16 '14 at 18:37
The log shows you never authenticated. The question is ... why? – David Schwartz Jan 16 '14 at 21:45
up vote 2 down vote accepted

Set smtpmail-smtp-user, smtpmail needs it to look up credentials in the authinfo file.

share|improve this answer
This was the final little push I needed to fix the authentication issue. Thank you! – tlake Jan 26 '14 at 11:37

Two things are strange about the SMTP output at the top of the question:


The server proposes STARTTLS, even though you've set smtpmail-stream-type to ssl and therefore should have an encrypted connection already. I'm not sure how to check whether this is the case, and if not, how to fix this.

There is some terminology confusion here: SSL and TLS are actually basically the same thing. SSL version 3.0 and TLS version 1.0 are very similar protocols, and you rarely need to care about the difference. STARTTLS is a way of setting up an encrypted connection: instead of the connection being encrypted from the start, the connection starts out unencrypted, the server offers encryption, the client accepts it, and then they negotiate an encrypted connection. However, for some reason almost all mail clients use "SSL" to refer to non-STARTTLS encrypted connections (SSL or TLS), and "TLS" to refer to STARTTLS-encrypted connections. Emacs does not, so it might be worth trying setting smtpmail-stream-type to starttls.


The server proposes GSSAPI as the only authentication method, but smtpmail only supports PLAIN, LOGIN and CRAM-MD5. Unless the server would propose other authentication methods on encrypted connections, it seems like you're out of luck trying to send email from Emacs through this server.

share|improve this answer
Doesn't exactly solve my problem, but it does clear several things up and increase my comprehension. While the server does indeed try to impose GSSAPI, a conversation with the sysadmin revealed that the server also supports PLAIN. I did still need to use STARTTLS in some fashion, anyway. Thanks! – tlake Jan 26 '14 at 11:36

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.