Finn Smith
Finn Smith

Reputation: 883

Using sendEmail with second alias from getAliases()

I have several aliases associated with my Google Apps for Education account at work. getAliases gets them all, which is nice, but when I try to send an email from them using sendEmail, it only seems to work with the first alias, which is my personal one. If I try it using any alias other than [0], nothing happens, and I don't get an error.

Upvotes: -1

Views: 2296

Answers (2)

muds
muds

Reputation: 526

I had a similar issue and was racking my brain, only to realise I'd been using MailApp and not GmailApp.

This may not solve everyone's problem, but it's just to add to a checklist of possible mistakes someone may have made.

Upvotes: 1

Mogsdad
Mogsdad

Reputation: 45750

This is the example from getAliases(). WFM.

// Log the aliases for this Gmail account and send an email as the first one.
var me = Session.getActiveUser().getEmail();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
if (aliases.length > 0) {
  GmailApp.sendEmail(me, 'From an alias', 'A message from an alias!', {'from': aliases[0]});
} else {
  GmailApp.sendEmail(me, 'No aliases found', 'You have no aliases.');
}

Upvotes: 0

Related Questions