admin管理员组

文章数量:1417426

For some reason the Gmail API won't send an html email. Sending plaintext works fine:

var message = 'From: Me <[email protected]>\r\n' +
    'To: Me <[email protected]>\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 <[email protected]>\r\n' +
    'To: Me <[email protected]>\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 pliant?

For some reason the Gmail API won't send an html email. Sending plaintext works fine:

var message = 'From: Me <[email protected]>\r\n' +
    'To: Me <[email protected]>\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 <[email protected]>\r\n' +
    'To: Me <[email protected]>\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 pliant?

Share Improve this question asked Nov 6, 2014 at 0:50 robsrobs 571 silver badge4 bronze badges 5
  • How do you send mails using JavaScript? – Yang Commented Nov 6, 2014 at 1:11
  • I'm using javascript to send a post request to the Gmail API where the raw variable is the parameter in the request. Sorry, I realize I didn't really provide any context in the question. – robs Commented Nov 6, 2014 at 1:30
  • How are you creating rfc2822 string, message variable in the above example. I sit hard coded or Is there any other ways to that? @rob – Sasikanth Commented Mar 25, 2015 at 1:59
  • @robs, Are inline styles working for your? – user555 Commented Mar 26, 2015 at 7:09
  • Can I please see your full code? I have this exact same problem right now! – Penjimon Commented May 5, 2016 at 14:08
Add a ment  | 

1 Answer 1

Reset to default 4

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

本文标签: javascriptSend an HTML email using the Gmail APIStack Overflow