Karen Fisher
Karen Fisher

Reputation: 777

Google MailApp.sendEmail with another <sent from> field

Recently I did one script for the client.
Client give me permittion to necessary files.
That script finally sends email to specific adress.
And when I tested it in under my google account it sends email with my gmail adress in the "sent from" field.
When my client begin to use this script the "sent from" field still was mine!
I asked client to unshare files with hope that it in this case google system will change this field with his adress, but it was useless.
The firing code:

MailApp.sendEmail(email,subject,body, {htmlBody: body, attachments: pdf});

There is no way to change field!
What I have to do to fix that behavior?

P.S. Perhaps it is a bug in google?
I made the issue

Upvotes: 1

Views: 3307

Answers (2)

Serge insas
Serge insas

Reputation: 46812

You don't give the context of your use case but could it be possible that the function that has the send email() call is called by a trigger.? (An installable trigger of course)

In that case, the email would always be sent by the user who created the trigger. If you did then it would be from your account.

Please tell us if it's the case.

Upvotes: 2

Amit Agarwal
Amit Agarwal

Reputation: 11278

You can modify the code to include the from: parameter in the advanced args as shown here.

MailApp.sendEmail(email,subject,body, {htmlBody: body, attachments: pdf, from:alias});

"alias" is either your Gmail address or any address connected to your Gmail account.

Upvotes: 1

Related Questions