Skip to main content

Prerequisites

Using SDK

This example is based on the Mailrify’s official mailrify-python SDK library.
1

Install SDK

pip install mailrify
2

Initialize SDK

Get the API key from the Mailrify dashboard and initialize the SDK.
import mailrify
from mailrify.models import SendEmailRequest

mailrify.api_key = "YOUR_API_KEY"
3

Send an email with a simple dict

params: mailrify.Emails.SendParams = {
    "from": "Your app <[email protected]>",
    "to": ["[email protected]"],
    "subject": "Welcome to Mailrify 🚀",
    "html": "<p>It works! 👋</p>",
    "text": "It works!",
    "headers": {
        "X-Custom-Header": "CustomValue"
    }
}

email: mailrify.Emails.SendResponse = mailrify.Emails.send(params)
print(email)
Custom headers are forwarded as-is. Mailrify only manages the X-Usesend-Email-ID and References headers.
4

Send an email with the helper request object

emailData = SendEmailRequest(
    from_="Your app <[email protected]>",
    to=["[email protected]"],
    subject="Welcome to Mailrify 🚀",
    html="<p>It works! 👋</p>",
    text="It works!"
)

email = mailrify.Emails.send(emailData)
print(email)

Adding contacts programatically

1

Get the contact book id

Get the contact book id from the Mailrify dashboard. Copy the contact book id.
2

Add contacts

mailrify.Contacts.create(contactId, {
    'email': '[email protected]',
    'firstName': 'John',
    'lastName': 'Doe'
})
3

Update contact

mailrify.Contacts.update(contactBookId, contactId, {
  firstName: "John",
  lastName: "Doe",
})