5

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?

Nah
  • 1,690
  • 2
  • 26
  • 46

1 Answers1

4

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] == "yourGroup@Domain.com"){
        var myGroupMail=alias[i];
        break;
      }
    }
  }
  if (myGroupMail != "yourGroup@Domain.com"){return false}
  GmailApp.sendEmail(toEmail,strSubject,strContent,{from : myGroupMail});
  • couldn't thank you enough, i was trying to use var alias = GmailApp.getAliases(); and {from : alias["yourGroup@Domain.com"]} but i couldn't understand why it can't work (kept sending from my main individual account. but your solution is perfect! thanks! – unacorn Dec 10 '20 at 16:37