gs.profile.notify API

The MessageSender class is the main symbol provided by the gs.profile.notify product.

class gs.profile.notify.MessageSender(context, userInfo)
Parameters:
  • context – The context of the message.
  • userInfo (Products.CustomUserFolder.interfaces.IGSUserInfo) – The person to send the message to.

The MessageSender is used to send a pre-written message to someone. To initialise the class pass in a context and a user-info for the person who is to receive the message.

send_message(self, subject, txtMessage, htmlMessage='',
fromAddress=None, toAddresses=None)
Parameters:
  • subject (str) – The subject (the Subject header) of the message.
  • txtMessage (str) – The plain-text (text/plain) version of the message.
  • htmlMessage (str) – The HTML version (text/html) of the message.
  • fromAddress (str) – The address the email is sent from (the From header).
  • toAddress (list or None) – The addresses the email is sent to (the Tp header).
  • If only the subject and txtMessage arguments are given then the message will be sent to the default email addresses of the user that was passed in when the message sender was initialised.
  • If the optional htmlMessage is provided then a multipart/alternative email message will be created (RFC 2046#section-5.1.4), with both the text and HTML forms of the message set.
  • The fromAddress sets who sent the message. If omitted the email address of the Support group is used [1].
  • Finally, the toAddress is a list of email addresses to send the notification to. If omitted the system will use default (preferred) addresses of the user that was passed in when the message sender was initialised [2].

The MessageSender does not, ultimately, send the message. Instead it formats the message [3], and then calls gs.profile.notify.notifyuser.NotifyUser. The gs.profile.notify.notifyuser.NotifyUser.send_message() method of this class sends the message on its way by calling the gs.email.send_email() function.

[1]The system will fail an assertion if it cannot find a user for the supplied fromAddress.
[2]The system will fail an assertion if a toAddress is used that does not belong to the user. The address may be unverified, but it must belong to the user.
[3]The core Python email module is used to format the message using MIME.