无法在量角器的电子邮件内容中使用换行符

时间:2018-12-12 11:03:20

标签: node.js protractor

在我的量角器脚本中,我有一个字符串,该字符串用于发送电子邮件,如下所示。

var resNoLocString="51 Cart Road #408, Missouri City, TX 77459aaaa,90 South Street, Southern Pines, NC 87-541aaaa,01 Cart Road #7708, Missouri City, TX 7659aaaa";
resNoLocString=resNoLocString.replace(/aaaa,?/g,"\n");
resNoLocString=resNoLoc.length+" were failed, and they are: "+"\n"+resNoLocString;
console.log(resNoLocString);
const msg1 = {
 to: ['xxxxx@gmail.com'],
 from: 'xxx@gmail.com',
 subject: 'Test Result', 
 text: resNoLocString, 
}; 
sgMail.send(msg1);

,但在收到的电子邮件中没有显示新行,如下所示

3 were failed, and they are:51 Cart Road #408, Missouri City, TX 77459 90 South Street, Southern Pines, NC 87-541 01 Cart Road #7708, Missouri City, TX 7659

但是当我在命令提示符下打印它时,它以新行显示。如果我使用下面的代码

var resNoLocString=resNoLoc.toString()
resNoLocString=resNoLocString.replace(/aaaa,?/g,"\n"+"\n");
resNoLocString=resNoLoc.length+"were failed, and they are: "+"\n"+"\n"+resNoLocString;
console.log(resNoLocString);

然后它将在新行中显示。但是,在收到的电子邮件和命令提示符中都显示了两个新行,如下所示。

3 were failed, and they are:

51 Cart Road #408, Missouri City, TX 77459

90 South Street, Southern Pines, NC 87-541 

01 Cart Road #7708, Missouri City, TX 7659

所以我如何将字符串与电子邮件内容中的仅一个换行符对齐。我的目的是接收以下格式的电子邮件内容

3 were failed, and they are:
51 Cart Road #408, Missouri City, TX 77459 
90 South Street, Southern Pines, NC 87-541 
01 Cart Road #7708, Missouri City, TX 7659

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用nodemailer并提供以下邮件选项:

let mailOptions = {
            from: 'XXX',
            to: 'XXX',
            subject: 'XXX',
            text: 'XXX',
            html: 'resNoLoc.length+" were failed, and they are:<br>+resNoLocString;',

          };