gs.email
Documentation¶
This is the core product for sending email from GroupServer via SMTP [1]. It is used by the groups to send email to the group members [2], and the user-profile system to send notifications [3].
Contents:
Configuration¶
The configuration for sending email is controlled by the
gsconfig.ini
file. The configuration options set up how the
system connects to the SMTP server [1]. Delivery of email
messages can be can be to a local server, a remote server, or
turned off entirely as shown in the configuration examples
below.
Options¶
hostname
(required):- The name of the SMTP server (
localhost
if the SMTP server is running on the same machine as GroupServer). port
(required):- The port that the SMTP server runs on (usually
25
). username
(optional):- The name of the user that logs into the SMTP server to send the
message. (Defaults to
None
.) password
(optional):- The password used to log into the SMTP server. (Defaults to
None
.) no_tls
andforce_tls
(both optional):Transport Layer Security (TLS) is the replacement to the Secure Sockets Layer (SSL). It can be used to encrypt the communication between GroupServer and the SMTP server. Normally the system will use TLS if it is available.
Setting the
no_tls
option toFalse
will force the GroupServer to connect to the SMTP server en clear, even if encryption is available. This may be useful if the SMTP server only accepts connections fromlocalhost
and it is running on the same machine as GroupServer.Setting the
force_tls
toTrue
forces GroupServer to use encryption to connect to the SMTP server. If TLS is not available then aRuntimeError
is raised.queuepath
(optional):- The path to the
Maildir
folder that stores all the messages before processing by the SMTP server. Defaults to/tmp/mailqueue
. processorthread
(optional):- If
True
(the default) then a separate thread will be started to handle the queue and pass the email messages on to the SMTP server. IfFalse
the email messages will just be written to the file inqueuepath
and not be processed (which is very useful for testing). xverp
(optional):- If
True
then XVERP will be used when the email messages are sent [2].
Examples¶
Setting up delivery to the local SMTP server, from the
GroupServer instance called main
:
[config-main]
smtp = local
[smtp-local]
hostname = localhost
port = 25
no_tls = True
queuepath = /tmp/main-mail-queue
xverp = True
Note: | There will be more than the smtp option for the
configuration of the main GroupServer
instance. However, the other options have been left out
for clarity. |
---|
Setting up delivery to a remote SMTP server, from the GroupServer
instance called production
:
[config-production]
smtp = remote
[smtp-remote]
hostname = remote.host.name
port = 2525
username = user_on_the_remote_server
password = password_on_the_remote_server
force_tls = True
queuepath = /tmp/production-mail-queue
processorthread = True
xverp = True
Setting up a test system to not send out email:
[config-test]
smtp = none
[smtp-none]
hostname = localhost
port = 25
queuepath = /tmp/test-mail-queue
processorthread = False
[1] | Configuration is handled by the gs.email.config
module. It uses the gs.config module to read
the configuration information
<https://github.com/groupserver/gs.config> |
[2] | For more information about XVERP see The Postfix VERP Howto. |
Troubleshooting¶
If mail is trapped in queuedir/new
look to see if
.sending_*
or .rejected_*
files have been created in the
same directory. If so, delete them and the mail should be
processed.
gs.email
API Reference¶
The main function used by external code in the send_email()
function. Internally it uses the mailer to send messages based
on the configuration.
send_email
¶
-
gs.email.
send_email
(sender, recipients, email)[source]¶ Send an email message to some recipients
Parameters: - sender (str) – The address of the person, or group, that is responsible for sending the email message. This will become the from-address on the envelope; it is separate from the From, Sender, and Reply-to addresses in the email message.
- recipients (str, tuple, list) – The address of the person who should receive the email
message, a
list
of recipients, or atuple
containing the addresses of the recipients. This will become the to-address on the envelope; it is separate from the To, CC, and BCC addresses in the email message. - email (str) – The email message, as a string. It needs to be a complete message with headers and a body.
Returns: None
.The
send_email()
function uses SMTP to send anemail
message to therecipients
, from thesender
, in batches ofgs.email.core.MAX_BATCH
recipients. The batching is necessary to prevent overwhelming the SMTP server (it makes management of the mail queue easier).
-
gs.email.core.
MAX_BATCH
= 50¶ The maximum number of email recipients in a batch.
Examples¶
Send an email from the support-address of the site to all the addresses of a GroupServer user:
eu = gs.profile.email.base.EmailUser(context, userInfo)
send_email(siteInfo.get_support_email(), eu.get_addresses(), emailMessage)
The gs.profile.notify.NotifyUser
class demonstrates how
to send an email message using send_email()
. The
gs.profile.notify.MessageSender
class demonstrates how
an email message is constructed using the standard Python
email
module.
Mailer¶
The gs.email.mailer.XVERPSMTPMailer
is loaded when the
configuration option xverp
is set to True
(see
Configuration). As its name implies, it turns on XVERP, so
the groups can be informed when an address bounces [1]. For
the most part the mailer is the same as that provided by
zope.sendmail.
-
class
gs.email.mailer.
XVERPSMTPMailer
(hostname='localhost', port=25, username=None, password=None, no_tls=False, force_tls=False)[source]¶ Sending messages to an SMTP server using TLS and XVERP
-
send
(fromaddr, toaddrs, message)[source]¶ Send a message
Parameters: Returns: None
send()
will send a message to the SMTP server, requesting that XVERP is used. This is effectively the same as thezope.sendmail.mailer.SMTPMailer.send()
method, exceptmail_options
is used to passXVERP
to the SMTP server. TLS is used where possible.
-
Configuration¶
The gs.email.config.create_emailUtilities()
function loads
the configuration used to connect to the outgoing SMTP server,
before loading an appropriate mailer.
-
gs.email.config.
create_emailUtilities
(instance_id=None)[source]¶ Create the utilities to send the email messages
Parameters: instance_id (str) – The indentifier for the GroupServer instance Returns: None
The
create_emailUtilities()
function loads thesmtp
section of the configuration of the instance specified byinstance_id
. If no instance is specified thengs.config.getInstanceId()
is used to determine the current instance. It then loads the following configuration options:hostname
port
username
password
no_tls
force_tls
queuepath
processorthread
xverp
If the XVERP option is
True
thengs.email.mailer.XVERPSMTPMailer
is registered as the utility used to connect to the SMTP host; otherwisezope.sendmail.mailer.SMTPMailer
is used. In either case the mailer is configured with the options in the config file.
[1] | For more information about XVERP see The Postfix VERP Howto <http://www.postfix.org/VERP_README.html> |
Changelog¶
2.2.0 (2015-03-17)¶
- Turning on lax-parsing of the config, to avoid issues with the presence (or absence) of the relay-address-prefix
2.1.2 (2014-10-24)¶
- Using GitHub as the canonical repository
- Naming the reStructuredText files as such
2.1.1 (2014-03-21)¶
- Adding a try-except block
2.0.1 (2012-07-28)¶
- Fixing a typing mistake
2.0.0 (2012-07-19)¶
Initial version. Prior to this sending email was carried out by some code in the ZMI.
Resources¶
- Code repository: https://github.com/groupserver/gs.email/
- Documentation: http://groupserver.readthedocs.io/projects/gsemail/
- Questions and comments to http://groupserver.org/groups/development/
- Report bugs at https://redmine.iopen.net/projects/groupserver/
Indices and tables¶
[1] | Receiving email is supported by the
gs.group.messages.add.base product
<https://github.com/groupserver/gs.group.messages.add.base> |
[2] | Sending email from groups is handled by the
gs.group.list.sender product
<https://github.com/groupserver/gs.group.list.sender> |
[3] | Notifications are sent by the
gs.profile.notify product
<https://github.com/groupserver/gs.profile.notify/> |