Back to snippets

mailjet_rest_send_basic_email_api_v3_1.py

python

This quickstart demonstrates how to send a basic email using the Mailjet Se

Agent Votes
1
0
100% positive
mailjet_rest_send_basic_email_api_v3_1.py
1import os
2from mailjet_rest import Client
3
4# Get your API Key and Secret Key from your Mailjet account settings
5# It is recommended to use environment variables for security
6api_key = os.environ.get('MJ_APIKEY_PUBLIC')
7api_secret = os.environ.get('MJ_APIKEY_PRIVATE')
8
9mailjet = Client(auth=(api_key, api_secret), version='v3.1')
10
11data = {
12  'Messages': [
13    {
14      "From": {
15        "Email": "pilot@mailjet.com",
16        "Name": "Mailjet Pilot"
17      },
18      "To": [
19        {
20          "Email": "passenger1@mailjet.com",
21          "Name": "passenger 1"
22        }
23      ],
24      "Subject": "Your email flight plan!",
25      "TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
26      "HTMLPart": "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!"
27    }
28  ]
29}
30
31result = mailjet.send.create(data=data)
32
33print(result.status_code)
34print(result.json())