Emacs includes a package for sending your mail to a SMTP server and have it take care of delivering it to the final destination, rather than letting the MTA on your local system take care of it. This can be useful if you don't have a MTA set up on your host, or if your machine is often disconnected from the internet.
Sending mail via SMTP requires configuring your mail user agent (see Mail Methods) to use the SMTP library. If you have not configured anything, then in Emacs 24.1 and later the first time you try to send a mail Emacs will ask how you want to send mail. To use this library, answer ‘smtp’ when prompted. Emacs then asks for the name of the SMTP server.
If you prefer, or if you are using a non-standard mail user agent,
you can configure this yourself. The normal way to do this is to set
send-mail-function (see Mail Sending) to the value you want to use. To use this library:
(setq send-mail-function 'smtpmail-send-it)
The default value for this variable is
which interactively asks how you want to send mail.
Your mail user agent might use a different variable for this purpose.
It should inherit from
send-mail-function, but if it does not,
or if you prefer, you can set that variable directly. Consult your
mail user agent's documentation for more details. For example,
(see Mail Variables).
Before using SMTP you must find out the hostname of the SMTP server to use. Your system administrator or mail service provider should supply this information. Often it is some variant of the server you receive mail from. If your email address is ‘firstname.lastname@example.org’, then the name of the SMTP server is may be something like ‘smtp.example.com’.
smtpmail-smtp-servercontrols the hostname of the server to use. It is a string with an IP address or hostname. It defaults to the contents of the SMTPSERVER environment variable, or, if empty, the contents of
smtpmail-default-smtp-servercontrols the default hostname of the server to use. It is a string with an IP address or hostname. It must be set before the SMTP library is loaded. It has no effect if set after the SMTP library has been loaded, or if
smtpmail-smtp-serveris defined. It is usually set by system administrators in a site wide initialization file.
The following example illustrates what you could put in ~/.emacs to set the SMTP server name.
;; Send mail using SMTP via mail.example.org. (setq smtpmail-smtp-server "mail.example.org")
SMTP is normally used on the registered “smtp” TCP service port 25. Some environments use SMTP in “Mail Submission” mode, which uses port 587. Using other ports is not uncommon, either for security by obscurity purposes, port forwarding, or otherwise.
smtpmail-smtp-servicecontrols the port on the server to contact. It is either a string, in which case it will be translated into an integer using system calls, or an integer.
The following example illustrates what you could put in ~/.emacs to set the SMTP service port.
;; Send mail using SMTP on the mail submission port 587. (setq smtpmail-smtp-service 587)