Google Apps Script - Can I send email from another account - google-apps-script

I have just implement a simple function to send email automatic when a google form is submitted, with my current account.
When I sign in with other google account and submit this form. I recieve an email with my account (not account is signed). Is there any way to send with the account is signed?

Edit: I think I misunderstood your question...
2 things to know:
When a script sends an email using a triggered function ( a form submit trigger in this case) the mail will always be sent by the account of the creator of the trigger.
As explained below, to get the email address of the user submitting a form you must be part of a google-apps domain.
If you are using your form in a GAFE or business Google Apps account then you can use the getRespondentEmail() method but as mentioned in the documentation this does not work for normal Gmail accounts.

Related

How do you automatically send an email on Google form submit, from the person who submitted the form and not the Google form owner?

After someone (authorised and not myself) submits the Google form I created, which sends an email out to whoever they want, it shows that I (the Google form owner) sent it out myself. Is there a way to remove my email and show the email of the person who submitted the form?
This is the code in Apps Script
function onFormSubmit(e) {
let responses = e.namedValues;
MailApp.sendEmail({
to: responses['Email'],
subject: responses['Subject'],
htmlBody: responses['Message'],
});
}
I believe it might involve using Google Cloud Projects and an API, but I have little/no experience with those.
The problem occurs because your script is using an installable trigger and the Google Apps Script Mail service, as the script is ran using the credentials of the user who create the trigger, in this case you.
In order to send an email using the form submitter email address as sender, one option is to use
Google Workspace accounts from the same domain
Service account
Domain wide delegation of authority
There might be other options to send the emails as the form submitter but all that have thinking about using Google Forms looks to be cumberstone.
A more simple option, still using Google Apps Script, is to create a web app and set it as run as the user accesing the web app.
The more simple solution to avoid showing your email address as the sender is to change the approach: use an alias with a generic name. To do this add an alias to your Gmail account, use GmailApp instead of MailApp and set the script to use the alias instead of your email address.

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.
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.
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.

Email verification using google app script and google forms

I have a google form app which has, among others, an email id field.I want to verify that the email entered by user is the email which belongs to him. Pls note: I DO NOT WANT TO VERIFY THE DOMAIN/SYNTAX OF EMAIL. All emails would be gmail ids, so if that helps, is there a way to send a mail validation link to their gmail accounts and on clicking the link, the entry is made to spreadsheet. Else its cancelled.
Also the link must be valid for limited time only.
Yes this is possible. You can publish a Google script as a web app and add the email address of the recipient as a query parameter to this app. When the user clicks the link, the app is called, the email is verified and the app itself can log an entry into the spreadsheet.

Proper use of formSubmitReply

I have a problem with a function that uses trigger formSubmitReply. I created this script to be able to receive notifications of the form that was filled, but when I get the email with the information, I received the email from my account. Is it possible that the script sends the email on behalf of the person who is filling out the form?
Thank You!
According to the documentation, Container-specific installable triggers execute under the identity of the user who created the trigger.
the onFormSubmit trigger is one of these, so this is normal behavior.
If you are using a googleApps account you can get the identity of the user filling the form, a warning will be shown in the form itself, but the mail itself will still be sent with your account
Another alternative would be to create your form using UiApp and run the webapp as 'the user accessing the App', then the email would be sent by the user's account, this webapp will ask for authorization before executing.

Google Apps Script - Send email as user submitting form data

Using Google Apps for business, I have a form that company users access on a google site. The users completes the form and submits. onSubmit, a script runs, collects the data and puts into a PDF and sends an email to me for review.
Right now when the email is sent, it comes to my inbox as me sending to me. I'd like to have it send as the user submitting the form. Can anyone point me in the direction to send as the user submitting the form.
permissions are set as followed:
The spreadsheet sharing option has anyone at company can find / view.
It's deployed as "execute the apps as:" User accessing the web app. And anyone at the company can access the app.
thoughts?
You can replace the form with an HtmlService or UiApp version that runs as the user, and then the email will come from them.
Assuming your are using Google Forms, I don't believe the function/script being run onSubmit is being run by the user who fills out the form, its being run by the owner of the script (you). As #Corey G stated, you can use HtmlService or UIApp to create a form, but takes much more time to create the form itself.