Behaviour between GmaiApp.sendEmail and GmailApp.createDraft

12 views
Skip to first unread message

Darren Ball

unread,
Oct 17, 2024, 10:01:11 AM (yesterday) Oct 17
to Google Apps Script Community
I have a template, quite large that I am testing with.   When I send the email using 

GmailApp.sendMail - the message is delivered and the inline html is fine (works as expected, styling intact).

When I save the exactly same html message as a draft - no formatting is applied (CSS style).

Has anyone encountered this?  I am curious as to what needs to be adjusted to ensure the draft appears as the sent message.

For example below, these messages do not appear the same.  
The sent message is fine and appears correct.  The draft seems to not adhere to the style sheet which is inline in <style> blocks.

function testSend() {
const temp = HtmlService.createTemplateFromFile('test2');
GmailApp.sendEmail('us...@example.com','Newsletter', 'This is the text version of the email',{htmlBody: temp.evaluate().getContent()});
GmailApp.createDraft('us...@example.com','Newsletter', 'This is the text version of the email', {htmlBody : temp.evaluate().getContent()});
}

Anyone that might have insight on why this happens, let me know!

Thanks,
Darren

Darren Ball

unread,
Oct 17, 2024, 10:21:52 AM (yesterday) Oct 17
to Google Apps Script Community
I should qualify this.  When looking at the draft in the email console - the content is not styled.   In this instance I am saving the draft to manually send.

When I retrieve the draft and get the message body, it is the same html that I want sent.   Just in the console and if I manually send this draft it is not formatted.

Darren Ball

unread,
Oct 17, 2024, 10:57:02 AM (yesterday) Oct 17
to Google Apps Script Community
I have discovered that if I retrieve the draft programmatically and send it, the formatting is fine.

This is only when I view the draft in the console and send it from there.  All formatting is lost.
Seems a Gmail drafts issue?  Very weird.
Reply all
Reply to author
Forward
0 new messages