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> |