0
votes

i am trying to send mails to some list of user using google apps-script.

I am taking the first draft mail and then mailing it to list of users present in the spreadsheet. But when i use ".getplainbody(); " function. It only copies the plain text in the draft.

function sendmail() 
{
    var drafts = GmailApp.getDraftMessages();
    Logger.log(drafts.length);
    var draft = drafts[0].getPlainBody();
    Logger.log(draft);

    GmailApp.sendEmail('[email protected]', 'subject', 'Hello' + '\n ' + draft);
}

I have also tried using the getbody() and then html with the message.

function sendmail() 
{
    var drafts = GmailApp.getDraftMessages();
    Logger.log(drafts.length);
    var draft = drafts[0].getBody();
    Logger.log(draft);

    GmailApp.sendEmail('[email protected]', 'subject', 'Hello' + '\n ' + {html: draft});
}

But this also gives me "[object Object]" in the inbox. Is there any other option to send the draft mail (not in plain text format)with proper format.

Thanks

1

1 Answers

2
votes

Try: GmailApp.sendEmail('[email protected]', 'subject', 'plaintext body', {htmlBody: draft});

You are missing the fourth parameter, 'Hello' + '\n ' + {html: draft} actually concatenates Hello \n with the {html: draft} object.