Mail is sent using SMTP (Simple Mail Transfer Protocol). If you are on a Unix machine, you will probably have a daemon running on your machine, which accepts mail on the default SMTP port. This usually works without problems.

On a typical desktop machine, however, there is no local SMTP daemon running, or it is not correctly configured. You can talk to the SMTP server of your ISP, however. This page describes how to do this using SmtpMail.


On my Windows NT machine, for example, this is my setup:

 (setq smtpmail-default-smtp-server ""
       smtpmail-local-domain "")
 (load-library "smtpmail")

Furthermore, you need to tell Emacs to use ‘smtpmail-send-it’ whenever you want to send mail.

If you are using MailMode (the default), add this:

 (setq send-mail-function 'smtpmail-send-it)

If you are using MessageMode (part of Gnus, see CategoryGnus), add this:

 (setq message-send-mail-function 'smtpmail-send-it)

Using Encryption

There are several ways to achieve encrypted communication with the server when sending emails. One possibility is to use SSL:

    (setq send-mail-function    'smtpmail-send-it
          smtpmail-smtp-server  ""
          smtpmail-stream-type  'ssl
          smtpmail-smtp-service 465)

Since no credentials are given in this configuration, Emacs will look them up in $(HOME)/.authinfo or $(HOME)/.authinfo.gpg (encrypted). The content of this file should follow this scheme:

    machine login [your login name] password [your password]

If the authinfo file is encrypted, Emacs will prompt you for the password when you send the first email but not when sending subsequent emails.

An alternative to SSL is STARTTLS:

    (setq send-mail-function    'smtpmail-send-it
          smtpmail-smtp-server  ""
          smtpmail-stream-type  'starttls
          smtpmail-smtp-service 587)

You can use the variable ‘gnutls-algorithm-priority’ to control which encryption algorithms should be used. For example the following setting restricts the range of algorithms that are offered to the server to those implementing perfect forward secrecy:

    (setq gnutls-algorithm-priority "PFS")

See the section about priority strings of the documentation of GnuTLS for details:

Fixing Issues

Some servers use sloppy implementations of the TLS and SSL standards and it may happen that connections are dropped unexpectedly. In these situations, it can help to update GnuTLS or to add a setting that allows GnuTLS? to be more forgiving with respect to deviations from the standards:

 (setq gnutls-algorithm-priority "NORMAL:%COMPAT")

See the section about priority strings of the documentation of GnuTLS? for details:


Here is another setup example:

 (setq smtpmail-default-smtp-server "smtpserver") ; needs to be specified before the (require)
 (require 'smtpmail)
 (setq send-mail-function 'smtpmail-send-it)
 (setq message-send-mail-function 'smtpmail-send-it)
 (setq user-full-name "Joe")
 (setq smtpmail-local-domain "")
 (setq user-mail-address (concat "Joe.R.User@" smtpmail-local-domain))

The manual for smtpmail.el can be found at

Emulators (eg. for Windows)

Those using CYGWIN might want to try the sSMTP Sendmail emulator, like this:

 (setq message-send-mail-function 'message-send-mail-with-sendmail)
 (if (equal system-type 'windows-nt)
    (setq sendmail-program "c:/cygwin/usr/sbin/ssmtp.exe"))

See also GnusMSMTP


Note that older versions of this library (eg. Emacs 20) do not allow authentification. You cannot provide usernames and passwords. Therefore there are lots of ways people try to stop abuse:

  1. If the server doesn’t like your IP address it might answer “Relaying denied” and refuse to send your mail
  2. If the server wants to fake it, they might ask you to fetch mail before trying to send any. The reason is that when you are GettingMail, you will need a username and a password.

Later versions of this library support the variable ‘smtpmail-auth-credentials’. See SmtpAuth.

Mail queueing

Sometimes, it can be useful to just queue the mails and send them later all at once (dialup users, etc…), then just add:

(setq smtpmail-queue-mail t)

When your network connection is ready, just do

M-x smtpmail-send-queued-mail RET

No Address Rewriting

If your smtp server is a non-address-rewriting MTA (like the qmail default), and if you’d like your domain name to be added automatically to the addresses, see SendMailAddressRewrite.

Managing Multiple SMTP Accounts

Unfortunately, there doesn’t exist a built-in feature to set the will be used SMTP server by looking at the “From:” line of the current post. But you can easily implement yours via mail hooks. See MultipleSMTPAccounts.

If you have more than one email address and have to send them using different SMTP servers, then you might want to take a look at esmtpmail.el a fork from smtpmail.el

See also: WritingMail

CategoryMail WThirtyTwoSendMAPI