简体   繁体   English

使用Gmail API发送HTML电子邮件

[英]Send an HTML email using the Gmail API

For some reason the Gmail API won't send an html email. 由于某些原因,Gmail API无法发送html电子邮件。 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)

Then when I try html, it just shows up as an empty message: 然后,当我尝试html时,它只是显示为空消息:

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)

Any ideas? 有任何想法吗? Maybe because it's not RFC 2822 compliant? 也许是因为它不符合RFC 2822?

For starters you need to use base64url encoding, using the web/url safe alphabet not just the standard btoa() base64. 对于初学者,您需要使用base64url编码,不仅要使用标准的btoa()base64,还要使用Web / URL安全字母。 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?) (或者它能正常工作并且不能显示为html吗?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 gmail api使用html中的内容发送电子邮件 - gmail api send email using content in html 使用Gmail API和Javascript发送HTML格式的电子邮件 - Send HTML formatted email using Gmail API and Javascript 使用Typescript / Javascript中的Gmail API发送电子邮件 - Send an email using Gmail API in Typescript/Javascript 如何使用客户端 gmail API 发送电子邮件,其中包含 html 内容和图像作为附件 - How to send an email using client side gmail API which have html content and an image as attachment 使用 gmail api 发送电子邮件不起作用 - send email with gmail api not working 如何使用Gmail API和Javascript发送结构化电子邮件标记? - How to send structured email markup using Gmail API and Javascript? Sending email with plain text, attachments and html using gmail api in reactjs - Sending email with plain text, attachments and html using gmail api in reactjs 有没有一种方法可以使用HTML通过gmail发送电子邮件 - is there a way to use HTML to send an email via gmail JavaScript-Gmail API-发送带有附件的电子邮件 - JavaScript - Gmail API - Send email with attachment 使用gmail api发送电子邮件错误:此API不支持解析表单编码输入 - send email using gmail api Error: This API does not support parsing form-encoded input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM