Send HTML using Gmail API

For some reason, the Gmail API will not send an html email address. 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 displays 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 does not comply with RFC 2822?

+2
source share
1 answer

First you need to use base64url encoding using the safe web / url alphabet, and not just the standard btoa () base64 base. If this does not help, can you post your code and the exact error message you receive? (Or does it work and not display as html?)

+4
source

Source: https://habr.com/ru/post/1619103/


All Articles