$(function () { pageContext.i18n.modTalk = 'moderation talk'; pageContext.i18n.replyToComment = 'Reply'; pageContext.i18n.modTalkEmpty = 'moderation talk is empty'; pageContext.url.getModTalk = "/comments/%25ID%25/listModTalk.json"; pageContext.url.possibleCommentRecipients = "/comments/%ID%/possibleRecipients.json"; pageContext.url.commentEdit = '/comments/%25ID%25/edit.html'; pageContext.url.commentView = '/comments/%ID%/view.html'; pageContext.i18n.commentVisibility = { 'full': 'Viewable by all users', 'op': 'Viewable by the original poster', 'mod': 'Viewable by moderators', 'opAndMod': 'Viewable by moderators and the original poster', 'other': 'Advanced visibility', 'dialogTitle': 'Comment visibility', 'selectGroups': 'Visible to groups', 'selectOther': 'Other recipients', 'selectOriginalPoster': 'Original poster', 'selectModerators': 'Moderators', 'selectAssignees': 'Asked to answer users' }; pageContext.i18n.commentMenuLabels = { 'comment-edit': 'comments.menu.edit', 'comment-delete': 'comments.menu.delete', 'comment-convert': 'comments.menu.convert' };pageContext.i18n.answer= { bestAnswer: 'Best Answer', controlBar : { accept: 'Accept', unaccept: 'Unaccept', acceptCommand: 'Accept this answer as correct', cancelAcceptedCommand: 'Remove this answers accepted status' } }; window.croles = { u: false, op: false, m: false, og: false, as: false, ag: false, dc: false, doc: false, eo: false, ea: false }; tools.init({ q: { e: false, ew: false, eo: false, r: false, ro: false, d: false, dow: false, fv: false, c: false, co: false, p: false, tm: false , ms: false, mos: false }, n: { f: false, vf: false, vfo: false, vr: false, vro: false, c: false, co: false, vu: false, vd: false, w: false, wo: false, l: false }, c: { e: false, eo: false, d: false, dow: false, ta: false, tao: false, l: false }, a: { e: false, ew: false, eo: false, d: false, dow: false, a: false, aoq: false, ao: false, tc: false, tco: false, p: false, tm: false }, pc: croles }, { tc: true, nsc: true }); commandUtils.initializeLabels(); }); Skip to Content
0

How to use the SMTP Outbound API of XSJS?

Apr 17, 2017 at 02:15 PM

133

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Florian Pfeffer
Apr 17, 2017 at 05:23 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded