javascript - gmail api send email using content in html - Stack Overflow

I am using the gmail api to send emails. The following is my codefunction sendEmail(auth, from, to, sub

I am using the gmail api to send emails. The following is my code

function sendEmail(auth, from, to, subject, content) {

 var encodedEmail = new Buffer(
   'From: ' + from + '\r\n' +
   'To: ' + to + '\r\n' +
   'Subject: ' + subject + '\r\n\r\n' +

   content 
 ).toString('base64').replace(/\+/g, '-').replace(/\//g, '_');

 var gmail = google.gmail('v1');
 var request = gmail.users.messages.send({
   auth: auth,
   userId: 'me',
   resource: {
     raw: encodedEmail
   }
 });
};

But the content in this case should be plain/text. The problem is that I want to pass the 'content' in HTML format. Any suggestion on how I can solve this?

I am using the gmail api to send emails. The following is my code

function sendEmail(auth, from, to, subject, content) {

 var encodedEmail = new Buffer(
   'From: ' + from + '\r\n' +
   'To: ' + to + '\r\n' +
   'Subject: ' + subject + '\r\n\r\n' +

   content 
 ).toString('base64').replace(/\+/g, '-').replace(/\//g, '_');

 var gmail = google.gmail('v1');
 var request = gmail.users.messages.send({
   auth: auth,
   userId: 'me',
   resource: {
     raw: encodedEmail
   }
 });
};

But the content in this case should be plain/text. The problem is that I want to pass the 'content' in HTML format. Any suggestion on how I can solve this?

Share Improve this question asked Sep 16, 2016 at 21:01 Daniel MarínDaniel Marín 1232 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

You have to provide a content type in your message, or it will default to plain/text as you mentioned. Just add a Content-Type-header with the value text/html:

From: [email protected]
To: [email protected]
Subject: Foo bar
Content-Type: text/html; charset=UTF-8

<b> This is the content of the email </b>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742318399a4421306.html

相关推荐

  • javascript - gmail api send email using content in html - Stack Overflow

    I am using the gmail api to send emails. The following is my codefunction sendEmail(auth, from, to, sub

    8小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信