In nodemailer, How to format text email Body

ぃ、小莉子 提交于 2020-12-29 12:43:26

问题


I have text body in nodemailer. I want to format text in email.

 var mailOptions={
        to      : data.toAddress,
        cc      : data.ccAddress,
        bcc     : data.bccAddress,
        subject : data.subject,
        text    : data.message
    }
    smtpTransport.sendMail(mailOptions, function(error, response){
        if(error){
            callback(null, error);
        }else{
            callback(response);
        }
    });

For eg; inculde bullet style, bold specific word.

But in documentation I am not finding specific section.

Kindly let me know if any one has any idea on this.


回答1:


You just to add html:

const message = {
  from: "sender@server.com",
  to: "receiver@sender.com",
  subject: "Message title",
  text: "Plaintext version of the message",
  html: "<p>HTML version of the message</p>"
};
  • from - The email address of the sender. All email addresses can be plain ‘sender@server.com’ or formatted ’“Sender Name” sender@server.com‘, see Address object for details.

  • to - Comma separated list or an array of recipients email addresses
    that will appear on the To: field.

  • cc - Comma separated list or an array of recipients email addresses that will appear on the Cc: field.
  • bcc - Comma separated list or an array of recipients email addresses that will appear on the Bcc: field.

  • subject - The subject of the email. text - The plaintext version of
    the message as an Unicode string, Buffer, Stream or an
    attachment-like object ({path: ‘/var/data/…’}).

  • html - The HTML version of the message as an Unicode string, Buffer, Stream or an attachment-like object ({path: ‘http://…‘}).

  • attachments - An array of attachment objects (see Using attachments
    for details). Attachments can be used for embedding images as well.




回答2:


If u want to format text in email you must write this text using HTML syntax eg.

var message = "<p style='font-weight:bold;'> Hi. My name is John </p>";

var mailOptions={
    to      : data.toAddress,
    cc      : data.ccAddress,
    bcc     : data.bccAddress,
    subject : data.subject,
    text    : message
}
smtpTransport.sendMail(mailOptions, function(error, response){
    if(error){
        callback(null, error);
    }else{
        callback(response);
    }
});



回答3:


let mail = { to: email, subject: "Authentication key", text: "<p style='font-weight:bold;'> Hi. My name is John </p>", };

I tried the mention suggestion but the output I received is still just a string.



来源:https://stackoverflow.com/questions/37676814/in-nodemailer-how-to-format-text-email-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!