How To Send Email Through HubSpot CRM Using SMTP API

Zyxware default image1

We can send emails through HubSpot CRM using SMTP API. For sending email SMTP, first, we need to create the SMTP tokens.

Generate SMTP API Tokens

An API token provides both a username and password which can then be used to send email through the HubSpot SMTP API. We can create an SMTP token using the API link below.

https://api.hubapi.com/email/public/v1/smtpapi/tokens?hapikey=demo

Example: Use the following code for generating json code,

$post_arr = array(
    'createdBy' => '[email protected]',
    'campaignName' => 'Transactional Email For Test'
  );
  $post_json = json_encode($post_arr);
  $hubspot_api_url = 'https://api.hubapi.com/email/public/v1/smtpapi/tokens?hapikey=demo';
  $response = drupal_http_request($hubspot_api_url, 
   array('Content-Type' => 'application/x-www-form-urlencoded'),
   'POST', $post_json);

A sample json response is shown below,

{
  "userName": "[email protected]",
  "password": "3432fff8eljl1249fjjasdfnv3",
  "portalId": 11111,
  "emailCampaignId": 14862038,
  "createdAt": 1415660606232,
  "deleted": false,
  "createdBy": "[email protected]",
  "appId": 22709,
  "campaignName": "Test Transactional Email"
}

From there we get the SMTP Hostname, SMTP Port, SMTP User Name,SMTP Password. Now we can send emails through HubSpot CRM using these SMTP values.