As an outcome of this guide, you will schedule an email that will be sent to your inbox using the Infobip Email API.
Prerequisites
• Working Python 3 environment
Difficulty level
This guide assumes very basic knowledge of Python and basic familiarity with APIs.
Summary of the steps
• Install the Infobip API Python SDK.
• Import the Email Channel and create an Email Channel instance using your credentials.
• Use the Email Channel to schedule your email payload.
• Send an email and print the response to track its progress.
Install the Infobip API Python SDK
pip install infobip-api-python-sdk
Create an Email Channel instance
You’ll create the instance using your credentials, and access its methods to send email messages. In this case, we will use the send_email_message
method to add the Email payload and schedule it for delivery.
Step 1. Import the EmailChannel
.
from infobip_channels.email.channel import EmailChannel
Step 2. Create an EmailChannel
instance and add your base_url
and api_key
that you can access either from your Infobip account or from the Infobip API landing page, once logged in.
channel = EmailChannel.from_auth_params({
"base_url": "<your_base_url>",
"api_key": "<your_api_key>"
})
Step 3. Use the send_email_message
method to add the email payload. To schedule an email for later, you must include the send_at
parameter. When using the Python SDK, you can use a datetime.datetime()
instance, or a string in ISO format (yyyy-MM-dd'T'HH:mm:ss.SSSZ
) to specify the scheduled time. The scheduled time must not be more than 30 days into the future.
We recommend you put the send_email_message
method within a variable, so that you can print out the response.
email_response = channel.send_email_message({
"from": "[email protected]",
"to": "[email protected]",
"subject": "Hi there!",
"text": "This is a scheduled message!",
"send_at": "2024-05-15T15:00Z",
})
Step 4. Print the response to see what happened to your email.
print(sms_response)
Once you run the code, you should see the following 200 OK
response, and the email will be delivered at the time specified.
{
"bulk_id": "2h2541duirtkytr1q8nv",
"messages": [
{
"to": "[email protected]",
"message_id": "68o8945sozntppd74pnh8",
"status": {
"group_id": 1,
"group_name": "PENDING",
"id": 26,
"name": "PENDING_ACCEPTED",
"description": "Message accepted, pending for delivery."
}
}
]
}
For troubleshooting and analytics, use the auto-generated bulk_id
to fetch the entire bulk of messages, or the message_id
to fetch one specific message.