SendEmail script Google spreadsheets - multiple op

2019-08-18 23:47发布

I'm trying to send out an email from google spreadsheets with multiple options:

if I type first attachments and then htlmBody in the code, like below, the email goes out with the correct body content and structure but the two attachments don't appear

MailApp.sendEmail(recipient, subject,{attachments:[blob,blob1]} ,{htmlBody:html});

While if I type first htmlBody and then attachments in the code, like below, the email goes out with the body "[object Object]" but the two attachments are present!

MailApp.sendEmail(recipient, subject ,{htmlBody:html},{attachments:[blob,blob1]});

What am I doing wrong? Why I can't use both? And in the case i would need to add a "cc" option?

I already tried with only one attachment and the result is the same!

1条回答
劫难
2楼-- · 2019-08-19 00:12

https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String,Object)

GmailApp.sendEmail(recipient, subject , 'body if no html', {
     htmlBody:html, attachments: [blob,blob1]
 });

if you know they have HTML you can replace the no HTML body text with an empty string but the placeholder and empty string must be there.

GmailApp.sendEmail(recipient, subject , '', {
         htmlBody:html, attachments: [blob,blob1]
     });
查看更多
登录 后发表回答