CAT-SOOP API: catsoop.mail

Methods for sending e-mail from within CAT-SOOP

View Source

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): the smtplib.SMTP object to use; if none is provided, catsoop.mail.get_smtp_object is invoked to create one

    Returns: True if this instance is capable of sending e-mails (if it properly configured an smtplib.SMTP object and has a valid "From" address), and False otherwise

 

  • 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 address is sent, use that. Otherwise, if cs_url_root is a sensible URL, then use "no-reply@%s" % cs_url_root. Otherwise, return None.

    Parameters:

    • context: the context associated with this request

    Returns: a string containing a default "From" address, or None in 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, and cs_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 None if 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.SMTP object to use for sending e-mail, or None if 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 body as Markdown, and the plain-text portion will contain body verbatim.

    Parameters:

    • context: the context associated with this request
    • course: 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 recipient
    • subject: A string representing the subject of the e-mail message
    • body: A string representing the contents of the e-mail (plain text)

    Optional Parameters:

    • from_addr (default None): the "From" address to use; if none is provided, the result of catsoop.mail.get_from_address is 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 request
    • to_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 message
    • body: A string representing the contents of the e-mail (plain text)

    Optional Parameters:

    • html_body (default None): A string representing the contents of the e-mail in HTML mode, or None to send only a plain-text message
    • from_addr (default None): the "From" address to use; if none is provided, the result of catsoop.mail.get_from_address is used

    Returns: a dictionary containing error information

 

  • catsoop.mail.setup_smtp_object (function, lines 111-132)

    Helper function. Set up an smtplib.SMTP object for use with CAT-SOOP, enabling TLS if possible and logging in a user if information is specified.

    Parameters:

    • smtp: the smtplib.SMTP object to configure
    • user: the username to use when logging in
    • password: the password to use when logging in

    Returns: the same smtplib.SMTP object that was passed in, after configuring it.