Getting started with Cakemail Next-gen

This page will help you get started with Cakemail. You'll be up and running in a jiffy!

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.

Cakemail SDKs will automatically take care of the authentication mechanism, reusing the issued token and refreshing it when it expires.

Add your first 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.

Confirm your first sender

To use a sender, it must be confirmed. If the sender email address is the same as your login email address, the sender will automatically be confirmed.

Otherwise, a confirmation email is sent to the sender email address; simply click the activation link to confirm your 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!