Exscript.util.mail module¶
Sending and formatting emails.
-
class
Exscript.util.mail.
Mail
(sender=None, to='', cc='', bcc='', subject='', body='')[source]¶ Bases:
future.types.newobject.newobject
Represents an email.
-
__init__
(sender=None, to='', cc='', bcc='', subject='', body='')[source]¶ Creates a new email with the given values. If the given sender is None, one will be automatically chosen using getpass.getuser().
Parameters: - sender (string) – The email address of the sender.
- to (string|list(string)) – A list of email addresses, passed to set_to().
- cc (string|list(string)) – A list of email addresses, passed to set_cc().
- bcc (string|list(string)) – A list of email addresses, passed to set_bcc().
- subject (string) – A subject line, passed to set_subject().
- body (string) – The email body, passed to set_body().
-
add_attachment
(filename)[source]¶ Adds the file with the given name as an attachment.
Parameters: filename (string) – A filename.
-
add_bcc
(bcc)[source]¶ Like add_to(), but for the ‘bcc’ field.
Parameters: bcc (string|list(string)) – The list of email addresses.
-
add_cc
(cc)[source]¶ Like add_to(), but for the ‘cc’ field.
Parameters: cc (string|list(string)) – The list of email addresses.
-
add_to
(to)[source]¶ Adds the given list of receipients to the ‘to’ field. Accepts the same argument types as set_to().
Parameters: to (string|list(string)) – The list of email addresses.
-
get_attachments
()[source]¶ Returns a list of attached files.
Return type: list[string] Returns: The list of filenames.
-
get_bcc
()[source]¶ Returns the value of the “bcc” field.
Return type: list(string) Returns: The email addresses in the ‘bcc’ field.
-
get_cc
()[source]¶ Returns the value of the “cc” field.
Return type: list(string) Returns: The email addresses in the ‘cc’ field.
-
get_receipients
()[source]¶ Returns a list of all receipients (to, cc, and bcc).
Return type: list(string) Returns: The email addresses of all receipients.
-
get_sender
()[source]¶ Returns the value of the “From:” field.
Return type: string Returns: The email address of the sender.
-
get_smtp_header
()[source]¶ Returns the SMTP formatted header of the line.
Return type: string Returns: The SMTP header.
-
get_smtp_mail
()[source]¶ Returns the SMTP formatted email, as it may be passed to sendmail.
Return type: string Returns: The SMTP formatted mail.
-
get_to
()[source]¶ Returns the value of the “to” field.
Return type: list(string) Returns: The email addresses in the ‘to’ field.
-
set_bcc
(bcc)[source]¶ Like set_to(), but for the ‘bcc’ field.
Parameters: bcc (string|list(string)) – The email addresses for the ‘bcc’ field.
-
set_body
(body)[source]¶ Defines the body of the mail.
Parameters: body (string) – The new email body.
-
set_cc
(cc)[source]¶ Like set_to(), but for the ‘cc’ field.
Parameters: cc (string|list(string)) – The email addresses for the ‘cc’ field.
-
set_from_template_string
(string)[source]¶ Reads the given template (SMTP formatted) and sets all fields accordingly.
Parameters: string (string) – The template.
-
set_sender
(sender)[source]¶ Defines the value of the “From:” field.
Parameters: sender (string) – The email address of the sender.
-
set_subject
(subject)[source]¶ Defines the subject line.
Parameters: subject (string) – The new subject line.
-
set_to
(to)[source]¶ Replaces the current list of receipients in the ‘to’ field by the given value. The value may be one of the following:
- A list of strings (email addresses).
- A comma separated string containing one or more email addresses.
Parameters: to (string|list(string)) – The email addresses for the ‘to’ field.
-
-
Exscript.util.mail.
from_template
(filename, **kwargs)[source]¶ Like from_template_string(), but reads the template from the file with the given name instead.
Parameters: - filename (string) – The name of the template file.
- kwargs (str) – Variables to replace in the template.
Return type: Returns: The resulting mail.
-
Exscript.util.mail.
from_template_string
(string, **kwargs)[source]¶ Reads the given SMTP formatted template, and creates a new Mail object using the information.
Parameters: - string (str) – The SMTP formatted template.
- kwargs (str) – Variables to replace in the template.
Return type: Returns: The resulting mail.