CAT-SOOP API: catsoop.mail
Members
-
catsoop.mail.RE_URL (
Pattern)Regular expression to match a URL, to give a chance at guessing a reasonable default "from" address
-
catsoop.mail.can_send_email (
function, lines 135-154)Test whether CAT-SOOP can send e-mail as currently configured
Parameters:
context: the context associated with this request
Optional Parameters:
smtp(default-1): thesmtplib.SMTPobject to use; if none is provided,catsoop.mail.get_smtp_objectis invoked to create one
Returns:
Trueif this instance is capable of sending e-mails (if it properly configured ansmtplib.SMTPobject and has a valid "From" address), andFalseotherwise
-
catsoop.mail.get_from_address (
function, lines 35-60)Get the address that should be used for the "From" field in sent e-mails
If
cs_email_from addressis sent, use that. Otherwise, ifcs_url_rootis a sensible URL, then use"no-reply@%s" % cs_url_root. Otherwise, returnNone.Parameters:
context: the context associated with this request
Returns: a string containing a default "From" address, or
Nonein the case of an error.
-
catsoop.mail.get_smtp_config_vars (
function, lines 63-83)Helper function. Get the values of e-mail-related configuration variables from the given context.
In particular, this function looks for
cs_smtp_host,cs_smtp_port,cs_smtp_user, andcs_smtp_password. If those values are not provided, the function assumes it is connecting to localhost on port 25, and that no username or password are required.Parameters:
context: the context associated with this request
Returns: a 4-tuple
(hostname, port, username, password)
-
catsoop.mail.get_smtp_object (
function, lines 86-108)Return an SMTP object for sending e-mails, or
Noneif not configured to send e-mail.This function is actually also used as the primary means of detecting whether this instance is capable of sending e-mails (which controls certain behaviors, such as whether e-mail confirmations are required when signing up for an account under the
"login"authentication type.Parameters:
context: the context associated with this request
Returns: an
smtplib.SMTPobject to use for sending e-mail, orNoneif this instance is not capable of sending e-mail.
-
catsoop.mail.internal_message (
function, lines 201-237)Send an e-mail to a member of a course.
This function will send a multipart message. The HTML portion will consist of the result of interpreting the given
bodyas Markdown, and the plain-text portion will containbodyverbatim.Parameters:
context: the context associated with this requestcourse: the course associated with this request (where to look for user information for the recipient)recipient: the CAT-SOOP username (not e-mail address) of the indented recipientsubject: A string representing the subject of the e-mail messagebody: A string representing the contents of the e-mail (plain text)
Optional Parameters:
from_addr(defaultNone): the "From" address to use; if none is provided, the result ofcatsoop.mail.get_from_addressis used
Returns: a dictionary containing error information (empty on success), or a string containing an error message.
-
catsoop.mail.send_email (
function, lines 157-198)Helper function. Send an e-mail.
Parameters:
context: the context associated with this requestto_addr: A string containing a single e-mail address for the recipient, or an iterable containing multiple recipient addresses.subject: A string representing the subject of the e-mail messagebody: A string representing the contents of the e-mail (plain text)
Optional Parameters:
html_body(defaultNone): A string representing the contents of the e-mail in HTML mode, orNoneto send only a plain-text messagefrom_addr(defaultNone): the "From" address to use; if none is provided, the result ofcatsoop.mail.get_from_addressis used
Returns: a dictionary containing error information
-
catsoop.mail.setup_smtp_object (
function, lines 111-132)Helper function. Set up an
smtplib.SMTPobject for use with CAT-SOOP, enabling TLS if possible and logging in a user if information is specified.Parameters:
smtp: thesmtplib.SMTPobject to configureuser: the username to use when logging inpassword: the password to use when logging in
Returns: the same
smtplib.SMTPobject that was passed in, after configuring it.