Send Mail
You must configure the domains, email addresses, and the SMTP settings for an email client of your choice from the console. The code shown here enables you to send emails to the email addresses you specify from your Catalyst application.
Catalyst enables you to set multiple email addresses as the receivers, and to CC, BCC, and reply to through a single send mail operation. You can also attach files in your email. The maximum supported limits for email recipients and file attachments in a single send mail operation are specified below:
- To address: 10
- CC: 10
- BCC: 5
- Reply to: 5
- Number of file attachments: 5
- Size of file attachments: 15 MB (through a single file or multiple files upto 5 files)
Note: The subject, sender, and atleast one recipient email addresses are mandatory. Other attributes of the email are optional.
Create a JSON Configuration
You must initially create a JSON object containing the required attributes of the email. This includes the sender's email address and all the recipients of the email. You can also create file streams for the file attachments and pass them through the createReadStream() method, as well as specify the subject and content of the email as shown below.
Note: You must have configured and verified the sender's email address in the Catalyst console to be able to send emails. If the sender's email is hosted on a private domain or if you choose to use a third-party email client, you must configure them before sending emails as well.
The email reference used in the code below is the component instance created earlier.
Copiedlet fs = require('fs'); //Define the file stream for file attachments
//Create a config object with the email configuration
let config = {
from_email: 'emma@zylker.com',
to_email: ["vanessa.hyde@zoho.com","r.owens@zoho.com","chang.lee@zoho.com"],
cc:["p.boyle@zylker.com","robert.plant@zylker.com"],
bcc:["ham.gunn@zylker.com","rover.jenkins@zylker.com"],
reply_to:["peter.d@zoho.com","arnold.h@zoho.com"],
html_mode: true,
subject: 'Greetings from Zylker Corp!',
content: "<p>Hello,</p> We're glad to welcome you at Zylker Corp. To begin your journey with us, please download the attached KYC form and fill in your details. You can send us the completed form to this same email address.</p>We cannot wait to get started!<p><p>Cheers!</p><p>Team Zylker</p>",
attachments: [fs.createReadStream('kycform.pdf')] //create a file stream for the file attachment
};
Send the Email
You must now pass the JSON object to the sendMail() method as an argument as shown in the code below. This will initiate the email to be sent. The promise returned here will be resolved to an object as a JSON.
Copied//Send the mail by passing the config object
let email = catalystApp.email();
let mailPromise = email.sendMail(config);
mailPromise.then((mailObject) => {
console.log(mailObject);
})
.catch((err) => {
context.log(err);
});
A sample response that you will receive for different versions of Node.js is shown below:
Node.js
Copied{
isAsync: false,
project_details: { project_name: "Onboarding", id: 2136000000007733 },
from_email: "emma@zylker.com",
to_email: ["vanessa.hyde@zoho.com","r.owens@zoho.com","chang.lee@zoho.com"],
cc:["p.boyle@zylker.com","robert.plant@zylker.com"],
bcc:["ham.gunn@zylker.com","rover.jenkins@zylker.com"],
reply_to:["peter.d@zoho.com","arnold.h@zoho.com"],
html_mode: true,
subject: "Greetings from Zylker Corp!",
content: "<p>Hello,</p> We're glad to welcome you at Zylker Corp. To begin your journey with us, please download the attached KYC form and fill in your details. You can send us the completed form to this same email address.</p>We cannot wait to get started!<p><p>Cheers!</p><p>Team Zylker</p>"
}
Copied{
isAsync: false,
project_details: { project_name: "Onboarding", id: "2136000000007733" },
from_email: "emma@zylker.com",
to_email: ["vanessa.hyde@zoho.com","r.owens@zoho.com","chang.lee@zoho.com"],
cc:["p.boyle@zylker.com","robert.plant@zylker.com"],
bcc:["ham.gunn@zylker.com","rover.jenkins@zylker.com"],
reply_to:["peter.d@zoho.com","arnold.h@zoho.com"],
html_mode: true,
subject: "Greetings from Zylker Corp!",
content: "<p>Hello,</p> We're glad to welcome you at Zylker Corp. To begin your journey with us, please download the attached KYC form and fill in your details. You can send us the completed form to this same email address.</p>We cannot wait to get started!<p><p>Cheers!</p><p>Team Zylker</p>"
}