0

I have a Google script that sends mails given some data in a Spreadsheet. The mail is sent with GmailApp using an alias set on Gmail settings. This alias is a PEC, the italian "certified mail account".

This is the function that sends the mail

var aliases = GmailApp.getAliases()
var fileXML = DriveApp.getFileById(xmlId);

var subject = fileXML.getName().slice(0, fileXML.getName().length - 4);

GmailApp.sendEmail
(
  toMailPECAddress,
  subject,
  '',
  {
    // Send from alias (PEC account)
    // Alias must be configured via GMail settings
    'from': aliases[0],
    'attachments': [fileXML]
  }
);

This always worked. Since a couple of weeks ago, when I started getting a "service unavailable: gmail" error.

So far I did these test:

  • re-generate the alias, to be sure that it is "verified"
  • check that I can send mail from alias from Gmail web page; the receiver gets a mail that is correctly sent from the alias' SMTP
  • send a mail via script with the exact same code but from my main Gmail account; no errors with that
  • use MailApp instead of GmailApp in script; the mail is sent without errors, but it is NOT sent from the alias SMTP

What can be the problem?

Is there any new limitation that doesn't allow to send mails from aliases, or from non standard SMTP (from a PEC in my case)?

1 Answer 1

2

There seems to be an issue on Google's end that's causing the error since removing the attachment from the code sends the email. What I recommend is to submit a bug report about it and for the meantime, I've noticed that if you add something on the body, the code works.

From:

var aliases = GmailApp.getAliases()
var fileXML = DriveApp.getFileById(xmlId);

var subject = fileXML.getName().slice(0, fileXML.getName().length - 4);

GmailApp.sendEmail
(
  toMailPECAddress,
  subject,
  '',
  {
    // Send from alias (PEC account)
    // Alias must be configured via GMail settings
    'from': aliases[0],
    'attachments': [fileXML]
  }
);

To:

var aliases = GmailApp.getAliases()
var fileXML = DriveApp.getFileById(xmlId);

var subject = fileXML.getName().slice(0, fileXML.getName().length - 4);

GmailApp.sendEmail
(
  toMailPECAddress,
  subject,
  ' ', // Add a blank space or any character
  {
    // Send from alias (PEC account)
    // Alias must be configured via GMail settings
    'from': aliases[0],
    'attachments': [fileXML]
  }
);
Sign up to request clarification or add additional context in comments.

3 Comments

Didn't try to add a body. Will test and report. It will be more than enough for me if it works. On the other side, I can't remove the attachment (dind't test either)
Just add a blank space in the body just like my sample above.
I tested the blank space in the mail body and it actually worked! Thanks for the super-easy hint!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.