1
votes

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.

2
Our company has recently started using GSuite. We have the daily task of sending fixed format emails. I thought about using Google Forms to simplify this task. First, I created Google Forms to enter the required items for the fixed format of the mail. Next, I created a function to send mail on script editor and configured a trigger. Then, when I tested the script, an email was sent. However, there was one point that was not as expected. The point is that the "From:" header of the sent mail is the Goole Form owner's email address.Eiichi ABIRU
I have to set the email address of the user who entered the value in Google Form. The function that sends mail uses the GmailApps class. However, when the function sends a mail using the GmailApps class, only the Goole Form owner's email address can be set in the "From:" header. The user who entered a value in Form and clicked the Submit button is logged in to GSuite. Is there a way to set the email address of the user who entered a value in Form and not the Goole Form owner's email address and clicked the Submit button?Eiichi ABIRU
Is there anything stopping you from setting up the form to record email addresses by default rather than trying to determine it via script?ross
Are you trying to send the email on behalf of the person that took and submitted the form? or are you trying to get their email? if that's the case, you will need to add a question for them to add their email, Forms does not let you get the form taker's email just from the response.AMolina
@ross I set up to record the email address of the user who used the form. However, it was not possible to send the e-mail by setting the e-mail address in the From: header.Eiichi ABIRU

2 Answers

0
votes

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.

0
votes

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.