使用Gmail API发送HTML电子邮件
问题描述:
由于某种原因,Gmail API不会发送HTML电子邮件。发送明文的工作正常:
For some reason the Gmail API won't send an html email. Sending plaintext works fine:
var message = 'From: Me <me@gmail.com>\r\n' +
'To: Me <me@gmail.com>\r\n' +
'Subject: Hello\r\n\r\n'
'World'
var raw = btoa(message)
然后当我试试html,它只是显示为空消息:
Then when I try html, it just shows up as an empty message:
var message = 'From: Me <me@gmail.com>\r\n' +
'To: Me <me@gmail.com>\r\n' +
'Subject: Hello\r\n'
'Content-Type: text/html; charset=utf-8\r\n' +
'Content-Transfer-Encoding: quoted-printable\r\n\r\n' +
'<html><body>' +
'<h1>World</h1>' +
'</body></html>'
var raw = btoa(message)
任何想法?也许是因为它不符合RFC 2822?
Any ideas? Maybe because it's not RFC 2822 compliant?
答
对于初学者,你需要使用base64url编码,使用web / url safe alphabet not not只是标准的btoa()base64。如果这不能解决,你可以发布你的代码和你得到的确切错误消息吗? (或者它是否有效并且不显示为html?)
For starters you need to use base64url encoding, using the web/url safe alphabet not just the standard btoa() base64. If that doesn't fix it can you post your code and the exact error message you're getting? (Or does it work and not show up as html?)