Skip to main content

Prerequisites

Using Flask

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 typing import Dict
from fastapi import FastAPI

mailrify.api_key = "YOUR_API_KEY"
3

Send email

app = FastAPI()

@app.post("/")
def send_mail() -> 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!"
  }
  email: mailrify.Emails.SendResponse = mailrify.Emails.send(params)
  return 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",
})