Send an HTML email using the Gmail API

女生的网名这么多〃 提交于 2019-12-10 10:37:37

问题


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)

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)

Any ideas? Maybe because it's not RFC 2822 compliant?


回答1:


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?)



来源:https://stackoverflow.com/questions/26769952/send-an-html-email-using-the-gmail-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!