简体   繁体   中英

Sign in as a Google Group to create an Installable Trigger for App Scripts

I have created a number of tools that use Installable Triggers to send emails. Because I'm the one who wrote the scripts, and created the triggers, those emails are all sent from my account.

I am wondering if there is a way to create those installable triggers, not as my own account, but as a Google Group account. Ideally, I would like for those triggered emails to be sent from the Group's account, as opposed to my own. I am an Owner of the Google Group that I would like to use, so if it's possible, I should have the appropriate security. I'm just not sure if there's a way to log in as the Group, so that I can create the triggers from the Group's account, and therefore have the emails sent from the Group's account. Is that possible?

You don't need to sign in your group in the script, you just need to add the group email to your gmail settings Send mail as:

样本

After adding it, a window will prompt you and add your group credentials there. After confirmation, you should be able to use that email as your parameter for sendEmail . See code below.

Code:

function sendEmailUsingGroupEmail() {
  var alias = GmailApp.getAliases();
  var groupEmail = "group@domain.com";
  var toEmail = "test@domain.com";
  var strSubject = "subject";
  var strContent = "this is content";
  
  // Check first if that email exists after adding
  if(alias.includes(groupEmail))
    GmailApp.sendEmail(toEmail,strSubject,strContent,{from: groupEmail});
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM