The SAP Cloud SDK enables the sending of emails from applications deployed on SAP Business Technology Platform (BTP) to your email servers. The destination service on SAP BTP enables you to define email servers accessible both publicly on the internet and On-Premise.
Step 1 - Install npm module
- Install the npm module @sap-cloud-sdk/mail-client to your project by running the following command
Code Snippet
1npm install @sap-cloud-sdk/mail-client
- Use the following command to load the module
Code Snippet
1const { sendMail } = require("@sap-cloud-sdk/mail-client");
Step 2 - Create destination configuratio in SAP BTP
- Create the destination configuration in SAP BTP for your mail server
- The following destination configuration is used to connect to the Ethereal mail server (https://ethereal.email)
- The additional properties of the destination are listed below...
mail.smtp.auth | true |
---|---|
mail.smtp.from | user@ethereal.email |
mail.smtp.host | smtp.ethereal.email |
mail.smtp.port | 587 |
mail.smtp.ssl.enabled | false |
mail.transport.protocol | smtp |


Note
Currently, only basic authentication is supported.Step 3 - Code to send email
- Create a MailConfig object that contains all the essential information of an email
- Send the email by calling the sendMail() function with mailConfig as argument
Note
For an On-Premise mail server, you MUST deploy the application to SAP BTP to make it work. Running in hybrid mode will not work for an On-Premise mail serverCode Snippet
12345678910111213141516
srv.on("sendEmail", async (req) => {
try {
const mailConfig = {
from: "user@ethereal.email",
to: "someone@anywhere.com",
subject: "e-mail subject",
text: "e-mail text",
};
sendMail({ destinationName: "maildestination" }, [mailConfig]);
return "OK";
} catch (error) {
console.log(error);
}
});
Step 4 - Sending multiple emails
Code Snippet
123
sendMail({ destinationName: "maildestination" }, [mailConfig, mailConfig]);
- To send emails in a sequence, set the parallel option to false
Code Snippet
123456
sendMail({ destinationName: "maildestination" }, [mailConfig], {
sdkOptions: {
parallel: false
}
});