Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Google Script Send email with group account

Tags:

I want to send an email with Google Script, but I need to use the public (group) mailbox,

I didn't find an example of sending email from the group account on the Google API, and I couldn't find the answer on the stack overflow. Could you please tell me if there is a method that use google script send email with group account?

like image 835
Arthur Huang Avatar asked May 03 '18 07:05

Arthur Huang


1 Answers

I have solved the problem. from "Account and import" add your group account then You can reference below code to test whether you can send an email in group account.

  var alias = GmailApp.getAliases();
  var num = alias.length-1;
  var myMail = getMyMail();

  if (num<0){
    return false
  }else{
    for (var i = 0;i <= num;i++){
      if (alias[i] == "[email protected]"){
        var myGroupMail=alias[i];
        break;
      }
    }
  }
  if (myGroupMail != "[email protected]"){return false}
  GmailApp.sendEmail(toEmail,strSubject,strContent,{from : myGroupMail});
like image 168
Arthur Huang Avatar answered Oct 11 '22 14:10

Arthur Huang