Sending email using SAP Cloud SDK


After completing this lesson, you will be able to:

  • Sending emails using SAP Cloud SDK

Sending emails using SAP Cloud SDK

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
npm install @sap-cloud-sdk/mail-client
  • Use the following command to load the module
Code snippet
const { 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 (
  • The additional properties of the destination are listed below...
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
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 server
Code snippet

srv.on("sendEmail", async (req) => {
  try {
    const mailConfig = {
      from: "",
      to: "",
      subject: "e-mail subject",
      text: "e-mail text",

    sendMail({ destinationName: "maildestination" }, [mailConfig]);
    return "OK";
  } catch (error) {

Step 4 - Sending multiple emails

Code snippet

sendMail({ destinationName: "maildestination" }, [mailConfig, mailConfig]);
  • To send emails in a sequence, set the parallel option to false
Code snippet

sendMail({ destinationName: "maildestination" }, [mailConfig], {
  sdkOptions: {
    parallel: false

Log in to track your progress & complete quizzes