Send Secure Transactional Emails via API from Zoho ZeptoMail

09/05/2024 01:22 PM - Comment(s) - By Jesus Sosa

remision_url = "https://www.zohoapis.com/books/v3/invoices/"+invoice_ID+"?accept=pdf&organization_id="+Org_ID;

download_file = invokeurl

[

url :remision_url

type :GET

connection:"books_all"

];

encryptedFile = zoho.encryption.base64Encode(download_file);

// Create the "from" map

from_map = Map();

from_map.put("address","from_email@expressautomations.com"); // same as Zepto Mail remitent

// Create the "to" map containing email_address map

email_address_map = Map();

email_address_map.put("address","to_email@expressautomations.com");

email_address_map.put("name","To Person Name");

to_map = Map();

to_map.put("email_address",email_address_map);

// Add the "to" map to a list

to_list = list();

to_list.add(to_map);

// Create the "cc" map containing email_address map

cc_email_address_map = Map();

cc_email_address_map.put("address","cc_email@expressautomations.com");

cc_email_address_map.put("name","CC Person Name");

cc_map = Map();

cc_map.put("email_address",cc_email_address_map);

// Add the "cc" map to a list

cc_list = list();

cc_list.add(cc_map);

// Create the "reply_to" map

reply_to_map = Map();

reply_to_map.put("address","reply_email@expressautomations.com");

reply_to_map.put("name","Replay Name");

// Create the "attachments" map and add it to a list

attachments_map = Map();

attachments_map.put("content",encryptedFile);

attachments_map.put("mime_type","application/pdf");

attachments_map.put("name","myReport.pdf");

//

attachments_list = list();

attachments_list.add(attachments_map);

// Add the map to the list

// Create the main map

email_json = Map();

email_json.put("from",from_map);

email_json.put("to",to_list);

email_json.put("to",cc_list);

email_json.put("reply_to",reply_to_map);

email_json.put("subject","Test Email");

email_json.put("htmlbody","<div><b> Test email sent successfully. </b></div>");

email_json.put("attachments",attachments_list);

// Set the headers

headers_map = Map();

headers_map.put("Accept","application/json");

headers_map.put("Content-Type","application/json");

headers_map.put("Authorization","Zoho-enczapikey asSwedfs2vfas1VR60grk23aosmGGuc+s5mgtUasv2ulHBgs2FqdtGfvE/cdon0XIVw/xSPZJQjJsQWsaat7mB1RgTAHh9kty18IACiF9mqRe1U4J3x17qnvhDzOVmRYkhdsJI0NzgVommliFs8n1g==");

// Convert the map to a JSON string if needed

email_json_string = email_json.toString();

info email_json_string;

// This will output the JSON as a string

zeptomail_emailSend = invokeurl

[

url :"https://api.zeptomail.com/v1.1/email"

type :POST

parameters:email_json_string

headers:headers_map

];

info zeptomail_emailSend;

}

Jesus Sosa

Share -