7

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.

Sawan Kumar
  • 327
  • 1
  • 5
  • 13

2 Answers2

6

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.

corneliouz Bett
  • 149
  • 1
  • 10
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);
    }
});
SkyQ
  • 380
  • 2
  • 9