4
votes

I send 200 emails to a community of students via a google-spreadsheet attached google script.

My mailing call is as follow :

MailApp.sendEmail(
  "[email protected]",             // targetEmail
  "HELLO FROM KING OF NIGERIA", // emailTitle
  "",                           // something
  // emailContentHTML
  { htmlBody:  "<b>Hello John</b><br><p>I'am king of Nigeria.<br>Got gold everywhere.<br>Need your help I'am in danger.<br>Want to share with you.<br>Could you send me 50$<br>Sinceraly, your friend.</p>"}
);

The script being run by my google account [email protected], the 200+ participants see the email as coming from me ([email protected]). I understand this is fair game to limit spamming and co, but my company has a gmail entreprise.com domain name and I would like a solution so to not get dozens of "Thanks you" alerts in the following days. For sure, I do NOT want them to keep me in their following discussion.

So I look for something such as create a [email protected] account, and then a js thing so the script sign email with this [email protected] email.

Also, is there a way to programatically sign the google-script mailing from an other account of my company ([email protected]) ?

Note : google-script-manual

3

3 Answers

2
votes

Since the script is being run under your Gmail account, the easiest way to do this is to add noReply: true to the message object. This will result in the email being sent from a generic [email protected] email. The noreply email account does not need to be created for this to work.

Note that this does not work for personal Gmail accounts.

The documentation for this is at this link as noted in Edward Wall's answer.

MailApp.sendEmail(
  "[email protected]",             // targetEmail
  "HELLO FROM KING OF NIGERIA", // emailTitle
  "",                           // something
  // emailContentHTML
  { htmlBody:  "<b>Hello John</b><br><p>I'am king of Nigeria.<br>Got gold everywhere.<br>Need your help I'am in danger.<br>Want to share with you.<br>Could you send me 50$<br>Sinceraly, your friend.</p>", 
  //send from generic [email protected] address
  noReply: true}
);
0
votes

The easiest way to send email from the [email protected] account is having the Apps Script will have to run under the authority of that account.

How you achieve this depends on how the script is being executed. If it is being executed by a Trigger, the Trigger must be created by the no-reply account.

If the script is published as a web-app, it should be deployed from the no-reply account, and set to execute as [email protected].

If the script is triggered manually, it will have to be triggered by somebody logged in as the no-reply user.

A simpler option is to set a reply-to address, as shown in Edward Wall's answer.

0
votes

You could use the following method from the MailApp documentation

sendEmail (title, replyTo, subject, body)

Setting the replyTo to your do-not-reply email will mean that anyone who presses reply will send their email to your do-not-reply mailbox

MailApp.sendEmail (
  "[email protected]",        // targetEmail
  "[email protected]", // reply to email
  ...
)

Link to MailApp Documentation