-2

I have the following code

  var mailOptions = {};
  mailOptions.attachments = attachmentArray;
  mailOptions.htmlBody = htmlbody;
  var alias = ??? // I have no idea what to put here. I've tried just putting in a string with the address
  mailOptions.from = alias;

  if(email){
  GmailApp.sendEmail(email, subject,"",mailOptions); 

I'm trying to send an email using an alias but I have multiple aliases to choose from. I saw somewhere that I can maybe use this

Gmail.Users.Settings.SendAs.Get

I should mention that while I wrote the script, I am not the owner of the spreadsheet. The original owner has a G Suite account, and wants to use their alias above. So it is not my alias, but they will be the one running the script.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Ryan Capule
  • 133
  • 1
  • 9
  • The documentation says that it's a string and it has to be one of the aliases that you have already created. If you had already created one you would know what to put there. – Cooper Dec 02 '20 at 23:40
  • 1
    The documentation is even more specific than what Cooper wrote: "the address that the email should be sent from, which must be one of the values returned by [getAliases()](https://developers.google.com/apps-script/reference/gmail/gmail-app#getAliases())" – Diego Dec 02 '20 at 23:41
  • So is what I want to do possible or not? I already read the documentation and I have no idea if this is possible/how to do it. – Ryan Capule Dec 03 '20 at 00:01

1 Answers1

0

First you should add an alias to Gmail. You can do this from the Gmail web app (see Send emails from a different address or alias) Also you might do this by using the Gmail API (see Managing Aliases

Once your Gmail account has one or more alias, you can use send email from an alias by adding its email address to the corresponing property of the GmailApp.sendEmail options argument.

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166