admin管理员组

文章数量:1278690

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

 var mailOptions={
        to      : data.toAddress,
        cc      : dataAddress,
        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.

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

 var mailOptions={
        to      : data.toAddress,
        cc      : dataAddress,
        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.

Share Improve this question asked Jun 7, 2016 at 10:27 Sawan KumarSawan Kumar 3271 gold badge6 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

You just to add html:

const message = {
  from: "[email protected]",
  to: "[email protected]",
  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 ‘[email protected]’ or formatted ’“Sender Name” [email protected]‘, 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.

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      : dataAddress,
    bcc     : data.bccAddress,
    subject : data.subject,
    text    : message
}
smtpTransport.sendMail(mailOptions, function(error, response){
    if(error){
        callback(null, error);
    }else{
        callback(response);
    }
});

本文标签: javascriptIn nodemailerHow to format text email BodyStack Overflow