Package trac :: Package notification :: Module mail

Module mail

source code

Classes
  RecipientMatcher
Matches user names and email addresses.
  EmailDistributor
Distributes notification events as emails.
  SmtpEmailSender
E-mail sender connecting to an SMTP server.
  SendmailEmailSender
E-mail sender using a locally-installed sendmail program.
  SessionEmailResolver
Gets the email address from the user preferences / session.
  AlwaysEmailSubscriber
Implement a policy to -always- send an email to a certain address.
  FromAuthorEmailDecorator
Implement a policy to use the author of the event as the sender in notification emails.
Functions
 
create_charset(mime_encoding)
Create an appropriate email charset for the given encoding.
source code
 
create_header(key, value, charset)
Create an email Header.
source code
 
set_header(message, key, value, charset)
Create and add or replace a header in a MIMEMultipart.
source code
 
create_mime_multipart(subtype)
Create an email MIMEMultipart.
source code
 
create_mime_text(body, format, charset)
Create a MIMEText that can be added to an email message.
source code
 
create_message_id(env, targetid, from_email, time, more=None)
Generate a predictable, but sufficiently unique message ID.
source code
 
get_message_addresses(message, name) source code
 
get_from_author(env, event)
Get the author name and email from a given event.
source code
Variables
  MAXHEADERLEN = 76
  EMAIL_LOOKALIKE_PATTERN = '[a-zA-Z0-9.\'+_-]+@(?:[a-zA-Z0-9_-]...
Function Details

create_charset(mime_encoding)

source code 

Create an appropriate email charset for the given encoding.

Valid options are 'base64' for Base64 encoding, 'qp' for Quoted-Printable, and 'none' for no encoding, in which case mails will be sent as 7bit if the content is all ASCII, or 8bit otherwise.

create_header(key, value, charset)

source code 

Create an email Header.

The key is always a string and will be converted to the appropriate charset. The value can either be a string or a two-element tuple where the first item is the name and the second item is the email address.

See set_header() for a helper that sets a header directly on a message.

set_header(message, key, value, charset)

source code 

Create and add or replace a header in a MIMEMultipart.

The key is always a string and will be converted to the appropriate charset. The value can either be a string or a two-element tuple where the first item is the name and the second item is the email address.

The charset should be created using create_charset()

Example:

set_header(my_message, 'From', ('Trac', 'noreply@ourcompany.com'),
           my_charset)

create_mime_multipart(subtype)

source code 

Create an email MIMEMultipart.

The subtype is a string that describes the type of multipart message you are defining. You should pick one that is defined by the email standards. The function does not check if the subtype is valid.

The most common examples are:

  • related infers that each part is in an integrated whole, like images that are embedded in a html part.
  • alternative infers that the message contains different formats and the client can choose which to display based on capabilities and user preferences, such as a text/html with an alternative text/plain.

The MIMEMultipart is defined in the email.mime.multipart module in the Python standard library.

create_mime_text(body, format, charset)

source code 
Create a MIMEText that can be added to an email message.
Parameters:
  • body - a string with the body of the message.
  • format - each text has a MIMEType, like text/plain. The supertype is always text, so in the format parameter you pass the subtype, like plain or html.
  • charset - should be created using create_charset().

create_message_id(env, targetid, from_email, time, more=None)

source code 

Generate a predictable, but sufficiently unique message ID.

In case you want to set the "Message ID" header, this convenience function will generate one by running a hash algorithm over a number of properties.

Parameters:
  • env - the Environment
  • targetid - a string that identifies the target, like NotificationEvent.target
  • from_email - the email address that the message is sent from
  • time - a Python datetime
  • more - a string that contains additional information that makes this message unique

get_from_author(env, event)

source code 

Get the author name and email from a given event.

The event parameter should be of the type NotificationEvent. If you only have the username of a Trac user, you should instead use the RecipientMatcher to find the user's details.

The method returns a tuple that contains the name and email address of the user. For example: ('developer', 'developer@ourcompany.com'). This tuple can be parsed by set_header().


Variables Details

EMAIL_LOOKALIKE_PATTERN

Value:
'[a-zA-Z0-9.\'+_-]+@(?:[a-zA-Z0-9_-]+\\.)+[a-zA-Z](?:[-a-zA-Z\\d]*[a-z\
A-Z\\d])?'