Eiichi ABIRU
Eiichi ABIRU

Reputation: 11

How to set user's email address in From: header using GmailApps class of Google Apps Script

I wrote a script to format the text that input on Google Forms and send it by email. The email could be sent but the email address of the user who entered the text cannot be set in the From: header.

I already read the Google Apps Script API documentation. And, I already know when I use the Gmail Apps class to send emails, I can set only the Google Form owner's email address in the "From:" header.

var options = {from: Session.getActiveUser().getEmail()};

GmailApp.sendEmail(to_address, subject, message, options);           

I want to set the email address of the user who entered the text in the From: header. However, my email address who is the owner of the form is set.

Upvotes: 1

Views: 393

Answers (2)

Wicket
Wicket

Reputation: 38424

It's very likely that you are using the on form submit installable trigger and in such case the GmailApp/MailApp services will send the email using the settings of the user who created the installable trigger.

To send an email on behalf of another user, instead you should use a more complex script. By one side you should use the Gmail Advanced Service, by the other side you should set this the domain-wide delegation for this script but this is only available for G Suite accounts and the domain-wide delegation requires G Suite Superadmin privileges.

Upvotes: 0

Aung49
Aung49

Reputation: 157

GMailApp (and MailApp) only allows you to use your own email address or an alias address linked with your account. This is to prevent people from acting like someone else by putting other people's addresses in the from field. If the script editor can freely change the From field, he could write anything he wants in the body and send it, posing as someone else.

Upvotes: 0

Related Questions