Email Library

These functions provide access to email services. The sending rate is limited to 20 emails per hour. Delivery will not be guaranteed for any sends beyond this rate. If you have your own Mandrill account, you can use the Mandrill Library instead and you won't have the limitation of 20 per hour.

 

Import

To use this library and its functions, you must use the import line at the beginning of your Base Python code.

import Email

 

Email Class

Email.Email(sender=None, display_name='', recipients=None, subject='', message='', attachments=None)

The Email class represents an email object.

Credit cost: 0

Parameters

  • senderstr email address of the sender. Must be 'no-reply@mediumone.com'.
  • display_namestr name of the sender to be displayed by the mail client
  • recipientsstr or [str] the recipient's email address. It also supports multiple email addresses separated by a semi-colon ';' or an array of strings.
  • subjectstr the email subject line
  • messagestr message (will default to text email if set).
  • attachmentsEmail.EmailAttachment object

Return Value

  • Email.Email

Exceptions

None


Attachment Class

Email.EmailAttachment(datacontent_typename)

The EmailAttachment class represents an email attachment object.

Credit cost: 0

Parameters

  • datastr base64 encoded string of the data to attach
  • content_typestr MIME Content-Type of the data being attached (for example 'image/jpeg;')
  • namestr a name to associate to the attachment

Return Value

  • Email.EmailAttachment

Exceptions

None

 

 

Set email text content

Email.Email.text_message(message)

Set the email message content to send as text. This overrides any message set during Email object creation.

Credit cost: 0

Parameters

  • messagestr the message string.

Return Value

None

Example

import Email
email = Email.Email('no-reply@mediumone.com','my name','you@mail.com','message subject')
email.text_message('from me to you... in text')
email.send()

Exceptions

None

 

Set email HTML content

Email.Email.html_message(message)

Set the email message content to send as HTML. This overrides any message set during Email object creation.

Credit cost: 0

Parameters

  • messagestr the HTML formatted message string.

Return Value

None

Example

import Email
email = Email.Email('no-reply@mediumone.com','my name','you@mail.com','message subject')
email.html_message('<!DOCTYPE html><html><title>Title</title><head></head><body><h2>From me to you,</h2><p> in HTML</p></body></html>')
email.send()

Exceptions

None

 

Set sender name

Email.Email.display_name(display_name)

Set the name of the sender. This overrides any sender's name set during Email object creation.

Credit cost: 0

Parameters

  • display_namestr the sender's display name.

Return Value

None

Example

import Email
email = Email.Email('no-reply@mediumone.com,'my name','you@mail.com','message subject')
email.display_name('my name too')
email.html_message('<!DOCTYPE html><html><title>Title</title><head></head><body><h2>From me to you,</h2><p> in HTML</p></body></html>')
email.send()

Exceptions

None

 

Add recipient

Email.Email.add_recipient(recipient)

Add a recipient's email to the list of recipients. This adds to the recipient's email list set during Email object creation.

Credit cost: 0

Parameters

  • recipientstr a recipient's email address.

Return Value

None

Example

import Email
email = Email.Email('no-reply@mediumone.com','my name','you@mail.com','message subject')
email.add_recipient('you2@mail.com')
email.html_message('<!DOCTYPE html><html><title>Title</title><head></head><body><h2>From me to you,</h2><p> in HTML</p></body></html>')
email.send()

Exceptions

None

 

Add attachment

Email.Email.add_attachment(attachment)

Add an attachment to the email. This adds to the attachment list.

Credit cost: 0

Parameters

  • attachmentEmailAttachment object.

Return Value

None

Example

import Email
email = Email.Email('no-reply@mediumone.com','my name','you@mail.com','message subject')
attachment = Email.EmailAttachment('iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', 'image/png;', 'image of a red dot')
email.html_message('<!DOCTYPE html><html><title>Title</title><head></head><body><h2>From me to you,</h2><p> in HTML</p></body></html>')
email.add_attachment(attachment)
email.send()

Exceptions

None

 

Send email

Email.Email.send()

Send the email message.

Credit cost: 1

Parameters

None

Returns

None 

Exceptions

  • EmailAPIException
    • Invalid email address
  • Exception
    • Email service down
  • AssertionError
    • No sender specified
    • No subject specified
    • No message specified
    • No recipient specified