[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2. Emacs Speaks SMTP

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 (@xref{Mail Methods,,,emacs}) to use the SMTP library. How to do this should be described for each mail user agent; for the default mail user agent the variable send-mail-function (@xref{Mail Sending,,,emacs}) is used; for the Message and Gnus user agents the variable message-send-mail-function (@xref{Mail Variables,,,message}) is used.

 
;; If you use the default mail user agent.
(setq send-mail-function 'smtpmail-send-it)
;; If you use Message or Gnus.
(setq message-send-mail-function 'smtpmail-send-it)

Before using SMTP you must find out the hostname of the SMTP server to use. Your system administrator should provide you with this information, but often it is the same as the server you receive mail from.

smtpmail-smtp-server
The variable smtpmail-smtp-server controls 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-server.

smtpmail-default-smtp-server
The variable smtpmail-default-smtp-server controls 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-server is 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-service
The variable smtpmail-smtp-service controls 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)


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs shared group account on December, 19 2009 using texi2html 1.65.