4

Okay this is very strange. I have scripting in a spreadsheet to take information from the currently active sheet, creates a report using a template file and sends it as an attachment.

This all works perfectly, when I use my Google apps domain account email address as the recipient. It doesn't work when I send to any other email address, other than my own. It was working yesterday. No errors generated when the script runs

The only thing that I did was change the owner of the spreadsheet to another user in our domain. It was shared with the other user while I was testing the scripts. I've tried using other email addresses in our domain and created a new spreadsheet with the sendemail function, all with the same behavior.

// Email the specified report
function emailReport(file, recipients, emailSubject, emailMessage) {
 MailApp.sendEmail("someone@example.com", emailSubject, emailMessage, 
              {attachments: file, mimetype: 'application/pdf'});
}
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
maxwondercorn
  • 123
  • 2
  • 9
  • Possible duplicate of [MailApp.sendEmail Not Working?](https://stackoverflow.com/questions/17355823/mailapp-sendemail-not-working) – Vega Nov 16 '18 at 15:57

3 Answers3

1

I've been able to reproduce the problem and to find a workaround.

As it's not posible to send email to recipients without google account, I add that kind of emails on a cc field.

// Email the specified report as cc
function emailReport(file, recipients, emailSubject, emailMessage) {
 MailApp.sendEmail("my@gmail.com", emailSubject, emailMessage, 
              {attachments: file, mimetype: 'application/pdf', cc:"someone@example.com"});
}
jrosell
  • 1,445
  • 14
  • 20
0

I noticed this question a while back, and even referenced it in another one. Since then I've noticed no one responded to you so...

It appears as if Google has recently changed (though not documented anywhere I've found) the MailApp.sendEmail function so that it only works when you use the email address belonging to the owner of the spread sheet.

My guess is this is to prevent the system being used for unsolicited mass emailing.

The other question was here

(Sorry, not an answer as such :( more of a confirmation as to what you are seeing seems to be as expected)

Community
  • 1
  • 1
Fashtas
  • 97
  • 2
  • 9
-1

For anyone having this issue, use the GmailApp class instead of the MailApp class.

It supports the same functions, for example: GmailApp.sendMail('recipient@gmail.com', 'Subject', 'Message').

https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String)

Easybird
  • 71
  • 1
  • 9
  • 1
    This did not solve my problem, which is the exact same as the OP: can only send email to my own email address. – GrayedFox Jan 20 '19 at 20:19