In this guide, we will show you how to send your first email with Cakemail Next-gen.
Working with our SDKs
To make it easier to integrate Cakemail Next-gen, we provide SDKs in various languages. For now, we provide SDKs for Python and PHP. Contact us if you would like a client in another language.
pip install cakemail
composer require cakemail/cakemail
Obtain your access token
The first step is to obtain a token. Tokens are required to make subsequent API calls. To obtain your token, you simply have to call the Create a token endpoint along with your Cakemail username and password.
curl --request POST \
--url https://api.cakemail.dev/token \
--data-urlencode grant_type=password \
--data-urlencode username=[Cakemail username] \
--data-urlencode password=[Cakemail password]
import cakemail
api = cakemail.Api(username='<Cakemail username>', password='<Cakemail password>')
<?php
$api = new \Cakemail\Api('<Cakemail username>', '<Cakemail password>');
This call, if successful, will return you a valid token containing:
- Access Token
- Token Type
- Expires In
- Refresh Token
The Access Token is what you will need to make the next API call. Before you can send your first email, you will need to create and confirm your first Sender. This step is required so we can make sure you have access to the mailbox of that sender.
Add your first confirmed sender
To create your first sender, you will call the Add a sender endpoint along with a name and an email address.
curl --request POST \
--url https://api.cakemail.dev/brands/default/senders \
--header 'accept: application/json' \
--header 'authorization: Bearer [access token]' \
--header 'content-type: application/json' \
--data '{"name":"[name]","email":"[email address]"}'
from cakemail.models import CreateSender
sender = api.sender.create(
CreateSender(name='<name>', email='<email address>')
)
<?php
$sender = $api->sender->create([
'create_sender' => new \Cakemail\Lib\Model\CreateSender([
'name' => '<name>',
'email' => '<email address>'
])
]);
This will return you a sender object that has an ID. It will also send an email to the email address you specified in the previous step. The email you will receive will contain a Confirmation ID. You can then call the Confirm a sender endpoint along with the sender ID and the confirmation ID to confirm your first sender.
curl --request POST \
--url https://api.cakemail.dev/brands/default/senders/[sender ID]/confirm-email \
--header 'accept: application/json' \
--header 'authorization: Bearer [access token]' \
--header 'content-type: application/json' \
--data '{"confirmation_id":"[confirmation ID]"}'
from cakemail.models import ConfirmSender
api.sender.confirm(
sender_id='<sender ID>',
confirm_sender=ConfirmSender(confirmation_id='<confirmation ID>')
)
<?php
$api->sender->confirm([
'sender_id' => $sender['id'],
'confirm_sender' => new \Cakemail\Lib\Model\ConfirmSender([
'confirmation_id' => '<Confirmation ID>'
])
]);
This last step is actually optional. Clicking the link included in the email will also confirm the sender.
Send your first email
You are now ready to send your first email! To do so, you will call the Send a transactional email endpoint. This call requires at the minimum the following information:
- Recipient Email Address
- Sender ID
- Subject Line
- Email Body
curl --request POST \
--url https://api.cakemail.dev/emails \
--header 'accept: application/json' \
--header 'authorization: Bearer [access token]' \
--header 'content-type: application/json' \
--data '{"sender":{"id":"[sender ID]"},"content":{"encoding":"utf-8","subject":"[subject line]","text":"[email body]"},"email":"[recipient email address]"}'
from cakemail.models import Email, EmailContent
api.transactional_email.send(
email=Email(
email='<recipient email address>',
sender=sender,
content=EmailContent(
subject='<subject line>',
text='<email body>',
encoding='utf-8'
)
)
)
<?php
$api->transactional_email->send([
'email' => new \Cakemail\Lib\Model\Email([
'email' => '<recipient email address>',
'sender' => $sender,
'content' => new \Cakemail\Lib\Model\EmailContent([
'subject' => '<subject line>',
'html' => '<email body>',
'encoding' => 'utf-8'
])
])
]);
Wow! You just sent your first email with Cakemail!
Updated 5 months ago
What's Next
Managing your contacts |