cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the SMTP Outbound API of XSJS?

Former Member
0 Kudos

Hi Guys,

I have been new to XS And from the reference guide I get to see the outbound API for sending emails.

subscribers = ["kofi@sap.com", "kwaku@sap.com"];

smtpConnection = new SMTPConnection();

var mail = new $.net.Mail(

{ sender: "manager@sap.com", subject: "Promotion Notice", subjectEncoding: "UTF-8",

parts: [new $.net.Mail.Part({

type: $.net.Mail.Part.TYPE_TEXT, contentType: "text/html", encoding: "UTF-8" })] });

for (var i = 0; i < subscribers.length; ++i)

{ mail.to = subscribers[i]; mail.parts[0].text = "Dear " + subscribers[i].split("@")[0] + ", \ you have been promoted. Congratulations!"; smtpConnection.send(mail); } smtpConnection.close();

Now when i copy the code and change the subscribers or the sender I get basic JS errors such as

subscribers was used before it was defined

smtpConnection was used before it was defined.

I want to know how to use these APIS

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

pfefferf
Active Contributor
0 Kudos

Depending on the type of IDE or editor with an integrated code syntax check like JSHint or ESLint you will get your message or a different message (like e.g. "subscribes is not defined"). This is because you didn't declare the "subscribers" and "stmpConnection" before you are using it.

Changing your code that "subscribers" and "smtpConnection" is declared with the "var" keyword (or "let" keyword in ES6), you will get rid off your errors. Just check the example of the current online help - SMPTConnection. Another question is why you need the extra path with the SMPTConnection and not just using the integrated send method of $.net.Mail (check the example here - $.net.Mail).

And of course SMTP has to be configured on your system, that the sending of mails will work.

Regards,
Florian