Skip to Content
0
Feb 03, 2023 at 10:41 AM

How to send out mail correctly with xsjs $.net.mail API?

129 Views

We are using $.mail API in our HANA XS application to implement mail notification, send out mail to target users. And receive request and feed back from user. Following is code for our implementation.

<code>function sendSingleTemplateMessage(system, template){
    var sended = {to : {addresses: [], counter: 0} , bcc : { addresses: [], counter : 0 }};
    
    var htmlConverter = new RegExp('\n', 'g');
    var doubleLines = new RegExp('\n\n', 'g');
    
    var subject = template.subject;
    
    template.text = template.text.replace(doubleLines, '\n').replace(htmlConverter, "</br>");
    
    template.to = template.to.filter(function(val) {
          return template.bcc.indexOf(val) === -1;
    });
    
    var i, mail;
    for( i= 0; i < template.to.length; i++){
        if(validateEmail(template.to[i])){
            mail = createMail(system, subject, template.to[i], null, template.text);
            mail.send();
            sended.to.addresses.push(template.to[i]);
            sended.to.counter = i;
        }
    }
    
    for( i= 0; i < template.bcc.length; i++){
        if(validateEmail(template.bcc[i])){
            mail = createMail(system, subject, null, template.bcc[i], template.text);
            mail.send();
            sended.bcc.addresses.push(template.bcc[i]);
            sended.bcc.counter = i;
        }
    }
    
    return sended;
}

The function is working perfectly earlier last year, but suddenly it's not functional any more. Mail can not reach the recipents, although the method is not throwing any error.

Here is SMTP Configuration in HANA Admin page.

enter image description here

I also tried other host url, like: sap-com.mail.protection.outlook.com. But still not working.

Has anyone encountered similar issue?

Best Regards

Dongcheng