使用Gmail API发送HTML电子邮件 [英] Send an HTML email using the Gmail API

查看:544
本文介绍了使用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?)

这篇关于使用Gmail API发送HTML电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆