Package entropy :: Module misc :: Class EmailSender

Class EmailSender

source code

This class implements a very simple e-mail (through SMTP) sender. It is used by the User Generated Content interface and something more.

You can swap the sender function at runtime, by redefining EmailSender.default_sender. By default, default_sender is set to EmailSender.smtp_send.

Sample code:

>>> sender = EmailSender()
>>> sender.send_text_email("[email protected]", ["[email protected]"], "hello!",
    "this is the content")
...
>>> sender = EmailSender()
>>> sender.send_mime_email("[email protected]", ["[email protected]"], "hello!",
    "this is the content", ["/path/to/file1", "/path/to/file2"])
Instance Methods
 
__init__(self)
EmailSender constructor
source code
None
smtp_send(self, sender, destinations, message)
This is the default method for sending emails.
source code
None
send_text_email(self, sender_email, destination_emails, subject, content)
This method exposes an easy way to send textual emails.
source code
None
send_mime_email(self, sender_email, destination_emails, subject, content, files)
This method exposes an easy way to send complex emails (with attachments).
source code
Method Details

smtp_send(self, sender, destinations, message)

source code 

This is the default method for sending emails. It uses Python's smtplib module. You should not use this function directly.

Parameters:
  • sender (string) - sender email address
  • destinations (list of string) - list of recipients
  • message (string) - message to send
Returns: None
None

send_text_email(self, sender_email, destination_emails, subject, content)

source code 

This method exposes an easy way to send textual emails.

Parameters:
  • sender_email (string) - sender email address
  • destination_emails (list) - list of recipients
  • subject (string) - email subject
  • content (string) - email content
Returns: None
None

send_mime_email(self, sender_email, destination_emails, subject, content, files)

source code 

This method exposes an easy way to send complex emails (with attachments).

Parameters:
  • sender_email (string) - sender email address
  • destination_emails (list of string) - list of recipients
  • subject (string) - email subject
  • content (string) - email content
  • files (list) - list of valid file paths
Returns: None
None