How To Send Email Through HubSpot CRM Using SMTP API

June 20, 2018 - 15:13

We can send email 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 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' => 'demo@hubspot.com',
    '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": "asdfghjkl@11111.smtp.hubspot.net",
  "password": "3432fff8eljl1249fjjasdfnv3",
  "portalId": 11111,
  "emailCampaignId": 14862038,
  "createdAt": 1415660606232,
  "deleted": false,
  "createdBy": "abcd@hubspot.com",
  "appId": 22709,
  "campaignName": "Test Transactional Email"
}

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

Post your comments / questions