Go to page content

Sending and receiving e-mail

Marc Worrell— 7 May 2012

On the Zotonic users e-mail list we got some questions about sending and receiving e-mail. Here is a copy of my explanation of the SMTP configuration of Zotonic.

Here is some more information about the configuration of SMTP for Zotonic. Sometimes the e-mail configuration is a bit confusing, as Zotonic can send and receive e-mail. Where most CMS systems can only send e-mail.

From priv/config.in I have copied the interesting bits and copied them below.

Sending e-mail

%% SMTP outbound relay configuration
% {smtp_relay, true},
% {smtp_host, "localhost"},
% {smtp_port, 2525},
% {smtp_ssl, true},

These define how to send your e-mail from Zotonic to other people.
Normally, when you don't set anything, Zotonic will use its own SMTP client for sending e-mail.
This works well and is the recommended way.

Only when you have to use your ISPs e-mailer or another SMTP server for sending e-mail you should start using an smtp_relay.

Sometimes an ISP blocks outgoing port 25 traffic, to stop spambots on PCs from sending e-mail.
And sometimes the IP range your server is in is mentioned on a blacklist.

In both cases you can enable the {smtp_relay, true} option and set the relevant bits.

%% SMTP extra relay options:
%% some picky/buggy/misconfigured relays might need one of these to be enabled
% {smtp_no_mx_lookups, false},
% {smtp_verp_as_from, false},
% {smtp_bounce_email_override, "me@example.com"},

These are only needed when you have problems sending e-mail through your SMTP server.
You will see appropriate errors in the e-mail log in the admin.

%% SMTP mail queue
%% How long to keep sent messages in the mail queue (in minutes)
%% Leave it long enough to receive any bounce message
% {smtp_delete_sent_after, 240},

When an e-mail is send we might need to resent it when a recoverable failure happens at the receiving party.
This setting tells how long we will keep your sent e-mail around, waiting for an error from the recipient.
After this period we will dispose your sent e-mail and are not able to re-sent it because of an error.

%% SMTP debug options
%% Send a copy of outgoing mail to this address
% {smtp_bcc, "bcc@localhost"},

Useful for debugging, receive a copy of all outgoing e-mail.

%% Send all mail to this address instead of the original recipient
% {email_override, "override@localhost"},

Useful for development.
This will override the original recipient of any outgoing e-mail message and instead sent it to this e-mail address.
We use it when we have a copy of a database and want to prevent to send any e-mail to people from this copy or development system.

Receiving e-mail

%% SMTP Inbound Server Options 
%% Always overruled by the environment variables ZOTONIC_SMTP_LISTEN_DOMAIN, ZOTONIC_SMTP_LISTEN_IP and ZOTONIC_SMTP_LISTEN_PORT
% {smtp_listen_domain, undefined},
% {smtp_listen_ip, "127.0.0.1"},
% {smtp_listen_port, 2525},

These settings are for RECEIVING e-mail from other systems by Zotonic.
Normally we listen on all IP addresses, port 2525 for incoming e-mail.

Using firewall rules (or other methods) you can redirect incoming traffic for port 25 to 2525 and start receiving e-mail.
You will need modules to handle the incoming e-mail.
When no module is enabled then all incoming e-mail is simple "black-holed" (ie. discarded) without any bounce message at all.

Example incoming e-mail modules are:

mod_email_relay
Relays e-mail send to an user's name to that user's e-mail address.
Other e-mail is discarded.

mod_email_receive
Adds infrastructure to generate unique e-mail addresses and register handlers for incoming e-mail on those addresses.
Check the notifications:
#email_ensure_handler{}, #email_add_handler{} and #email_drop_handler{}.

Please note that with the 0.9 release the message format for these handlers and the received e-mail will be refactored.