Send Mail

Steps

  1. Create a project mail_project.
  2. Create a JavaScript service with the name mail_service.js.
  3. Enter the following content:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var response = require("http/v4/response");
var mail = require("mail/v4/client");

var from = "from@email.address";
var to = "to@email.address";
var subject = "Subject";
var content = "<h1>Content<h1>";
var subType = "html";

mail.send(from, to, subject, content, subType);

response.println("Mail sent");

Note: This sample leverages the default mail configuration provided through the environment variables


  1. Create a project mail_custom_project.
  2. Create a JavaScript service with the name mail_custom_service.js.
  3. Enter the following content:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var response = require("http/v4/response");
var mail = require("mail/v4/client");

var mailConfig = {
	"mail.user": "<your-mailbox-user>",
	"mail.password": "<your-mailbox-password>",
	"mail.transport.protocol": "smtps",
	"mail.smtps.host": "smtp.gmail.com",
	"mail.smtps.port": "465",
	"mail.smtps.auth": "true"
};

var mailClient = mail.getClient(mailConfig);

var from = "<your-mailbox-user>@gmail.com";
var recipients = {
	to: "<your-mailbox-user>@gmail.com",
	cc: ["<your-mailbox-user>@gmail.com", "<your-mailbox-user-2>@sap.com"],
	bcc: "<your-mailbox-user>@sap.com"
};
var subject = "Subject";
var content = "<h1>Content</h1>";
var subType = "html";

mailClient.send(from, recipients, subject, content, subType);

response.println("Mail sent");

Note: This sample leverages Gmail SMTPS, to make this sample work, access from third party applications (Less secure apps) should be enabled, also Troubleshoot Problems could help


For more information, see the API documentation.

Edit