Home > front end >  Using MailApp to Send Email with Multiple Options
Using MailApp to Send Email with Multiple Options

Time:12-08

I am trying to use Mail.App to send an email with an html body, and combining it with the option to change the "from" name and "replyTo" email address.

My current script is:

MailApp.sendEmail (emailAddress, emailSubject, htmlBody, {htmlBody: htmlBody});

I believe I should add {from: "name", replyTo: "[email protected]"}. I end up with:

MailApp.sendEmail (emailAddress, emailSubject, htmlBody, {htmlBody: htmlBody}, {from: "name", replyTo: "[email protected]"});

But it gave me an error. What am I doing wrong?

CodePudding user response:

Just try:

 MailApp.sendEmail({
    to: "[email protected]",
    subject: "Logos",
    htmlBody: "inline Google Logo<img src='cid:googleLogo'> images! <br>"  
              "inline YouTube Logo <img src='cid:youtubeLogo'>});
 }

from this example: https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(Object)

Check the link you can add any of the options into the object

CodePudding user response:

There should only be one options object in there, like this:

  MailApp.sendEmail(emailAddress, emailSubject, htmlBody,
    { htmlBody: htmlBody, name: 'Tuyen Nguyen', replyTo: '[email protected]' });

MailApp expects the third parameter in the first line there to be a plain text version of the email you are sending. In the event the recipient's email program does not support HTML email for some reason, it will show the plain text version instead.

You are using the htmlBody variable for both the plain text version and the HTML version of the email message. That technically works, but be aware that some recipients may see HTML tags in their email messages.

See MailApp.sendEmail().

  • Related