Mandrill Library

The Mandrill Library works the same as the Email Library except it allows you to use your own Mandrill account so you're not subject to the 20 emails/hour limitation we enforce on the Email library. The only difference is in the send API described below, where you will specify your API key.

 

Import


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

import Mandrill

 

Functions

 

Mandrill.Email

Usage: Mandrill.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 (FROM attribute)
    • display_namestr name of the sender to be displayed by the mail client
    • recipientsstr or [str] the recipient's email address. Also supports multiple email addresses separated by a semi-colon ';' or an array of strings.
    • subjectstr the email subject line
    • message (optional): str message (will default to text email if set.
    • attachments (optional): Mandrill.EmailAttachment object
  • Returns:
    • Mandrill.Email



Mandrill.EmailAttachment

Usage: Mandrill.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
  • Returns:
    • Mandrill.EmailAttachment



Functions

 

Mandrill.Email.text_message

Usage: Mandrill.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.
      import Mandrill
      email = Mandrill.Email('me@mail.com','my name','you@mail.com','message subject')
      email.text_message('from me to you... in text')
      email.send(YOUR_MANDRILL_USERNAME,YOUR_MANDRILL_API_KEY)
  • Returns: None



Mandrill.Email.html_message

Usage: Mandrill.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.
      import Mandrill
      email = Mandrill.Email('me@mail.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(YOUR_MANDRILL_USERNAME,YOUR_MANDRILL_API_KEY)
  • Returns: None



Mandrill.Email.sender

Usage: Mandrill.Email.sender(sender)

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

  • Credit cost: 0
  • Parameters:
    • senderstr the sender's email address.
      import Mandrill
      email = Mandrill.Email('me@mail.com','my name','you@mail.com','message subject')
      email.sender('me2@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(YOUR_MANDRILL_USERNAME,YOUR_MANDRILL_API_KEY)
  • Returns: None
Mandrill.Email.display_name

Usage: Mandrill.Email.display_name(display_name)

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

  • Credit cost: 0
  • Parameters:
    • display_namestr the sender's display name.
      import Mandrill
      email = Mandrill.Email('me@mail.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(YOUR_MANDRILL_USERNAME,YOUR_MANDRILL_API_KEY)
  • Returns: None



Mandrill.Email.add_recipient

Usage: Mandrill.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.
      import Mandrill
      email = Mandrill.Email('me@mail.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(YOUR_MANDRILL_USERNAME,YOUR_MANDRILL_API_KEY)
  • Returns: None



Mandrill.Email.add_attachment

Usage: Mandrill.Email.add_attachment(attachment)

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

  • Credit cost: 0
  • Parameters:
    • attachmentEmailAttachment object.
      import Mandrill
      email = Mandrill.Email('me@mail.com','my name','you@mail.com','message subject')
      attachment = Mandrill.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(YOUR_MANDRILL_USERNAME,YOUR_MANDRILL_API_KEY)
  • Returns: None

 

Mandrill.Email.send

Usage: Mandrill.Email.send(username, apikey)

Send the email message.

  • Credit cost: 1
  • Parameters:
    • username: str Mandrill username.
    • apikey: str Mandrill API key.
  • Returns: None

 

Sample Code

 

import Mandrill

email = Mandrill.Email(‘me@mail.com’,’my_name’,’you@mail.com’,’message subject’)
email.text_message('from me to you... in text')
email.send(YOUR_MANDRILL_USERNAME,YOUR_MANDRILL_API_KEY)