Use the following Sample Code to send email using MassMailer Developer API:


Code Sample:


In this example, we have constructed a JSON string that is used as the input for the API to send emails.


String exampleJson = '{ "sender": { "fromName": "Siva Devaki", "fromAddress": "siva@massmailer.io", "replyTo": "siva@massmailer.io" }, "recipient": { "query": "SELECT Id FROM Contact where name = \'Siva Devaki\' ", "objectName": "Contact", "cc": "", "bcc": "" }, "options": { "unsubGroupId": null, "scheduleDateTime": null }, "email": { "subject": "Demo Subject", "text": "Demo Text", "template": "", "html": " ' + EncodingUtil.base64Encode(Blob.valueOf('<html><body>Sample HTML BODY</body></html>')) + '", "attachments": "" } }';


String responseJson = Cloudrop.MassMailerAPIService.sendEmail(exampleJson);

 

Map<String,Object> response = (Map<String, Object>) JSON.deserializeUntyped(responseJson);

String status = String.valueOf(response.get('status'));

Integer statusCode = Integer.valueOf(response.get('statusCode'));

Boolean isScheduled = Boolean.valueOf(response.get('isScheduled'));

String cronId = String.valueOf(response.get('cronId'));

String outreachStatisticsId = String.valueOf(response.get('statisticsId'));


JSON Structure with Example:


{

  "sender": {

    "fromName": "Siva Devaki",

    "fromAddress": "siva@massmailer.io",

    "replyTo": "siva@massmailer.io"

  },

  "recipient": {

    "query": "SELECT Id FROM Contact where name = 'Siva Devaki' ",

    "objectName": "Contact",

    "cc": "",

    "bcc": ""

  },

  "options": {

    "unsubGroupId": null,

    "scheduleDateTime": null

  },

  "email": {

    "subject": "Demo Subject",

    "text": "Demo Text",

    "template": "",

    "html": " ' + EncodingUtil.base64Encode(Blob.valueOf('<html><body>Sample HTML BODY</body></html>')) + '",

    "attachments": ""

  }

}


JSON Structure Explanation:


SenderfromName
Sender's name.

fromAddress
Sender's email address.

replyTo
Reply to email address.
recipient
query
The query that gives the recipients list.

objectName
The object to which you would like to send emails such as contact, lead. This needs to be the API name. 

cc
Any email addresses you want to copy.

bcc
Any email addresses you want to bcc.
options
unsubGroupId
This field denotes the unsubscribe group id.

scheduleDateTime
This field denotes the time you would like to schedule the email to go out.
email
subject
This field denotes the email subject.

text
This field denotes the text version of the email.

template
This field denotes the Salesforce Email Template Id if you want to use a template instead of sending the actual TEXT or HTML versions.

html
This field denotes the HTML version of the email.

attachments
This field denotes the Salesforce file Ids that are comma-separated. It can be a Salesforce attachment, Lightning file, Chatter file.