admin管理员组文章数量:1332361
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 badges1 Answer
Reset to default 9You 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>
本文标签: javascriptgmail api send email using content in htmlStack Overflow
版权声明:本文标题:javascript - gmail api send email using content in html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742318399a2452282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论