How do I use this `GmailApp.sendEmail` function?

Viewed 491

I have a Send Email Function(?) that I am using as a part of a Calendar Reservation Approval System. That function(?) looks like this:

// Send Email
function sendEmail(request){
  MailApp.sendEmail({
    to: request.email,
    subject: request.subject,
    htmlBody: makeEmail(request)
  })
}

Even that function(?) works fine. It runs without bugs etc. However, my account is self-censoring. Basically, my gsuite account is not sending email when coming from this script. I pay for gsuite, so I find this a bit boggling, but oh well, thats for another day.

Apparently this is the issue

Basically they say if I alter my existing script(?) to:

// Send Email
function sendEmail(request){
  GmailApp.sendEmail({
    to: request.email,
    subject: request.subject,
    htmlBody: makeEmail(request)
  })
}

Trouble is, that doesn't fire. So my thinking is that I need to make a minor alteration to the:

   to: request.email,
   subject: request.subject,
   htmlBody: makeEmail(request)

In order to get it back on track. I didn't write this so I haven't the faintest idea where to start. Anybody wanna help out a lost soul who spent the two hours getting here only to be hamstrung by google thinking I'm a spammer.

Thank you.

I researched the problem of the mail not being sent and figured out that GmailApp.sendEmail is the workaround.

1 Answers

You need to change your sendEmail method to:

GmailApp.sendEmail(request.email, request.subject, "", {htmlBody:makeEmail(request)});

The sendEmail() method uses the method's parameters (Documentation Here), only the aditional arguments (like the htmlBody) need to get passed as an object.

Related