13

I'm trying to use google app engine's mail service on my site. It's showing some error whenever I visit the page that sends the email. The error says that I am using an unauthorized sender for the message. Here's the code that sends the email:

mail.send_mail(sender="[email protected]",
     to=input_dict["email"],
     subject="Mondays user activation",
     body=content)

When I try out the site locally (using dev_appserver.py) it doesn't show the error, but it doesn't send the email (Note: I have to add the --enable_sendmail option when I try it locally). The error only shows up when I publish the site.

Does anybody know what I'm doing wrong? Thanks in advance for your help!

1
  • Very old thread but it solved my problem... just wanted to point out that your input_dict is a list :-P
    – s g
    Feb 19, 2016 at 3:07

4 Answers 4

27

What is [email protected]? You might not be able to send mail from that address.

App Engine applications can send email messages on behalf of the app's administrators, and on behalf of users with Google Accounts.

The email address of the sender, the From address. The sender address must be one of the following types:

  • The address of a registered administrator for the application. You can add administrators to an application using the Administration Console.

  • The address of the user for the current request signed in with a Google Account. You can determine the current user's email address with the Users API. The user's account must be a Gmail account, or be on a domain managed by Google Apps.

  • Any valid email receiving address for the app (such as [email protected]).

  • Any valid email receiving address of a domain account, such as [email protected]. Domain accounts are accounts outside of the Google domain with email addresses that do not end in @gmail.com or @APP-ID.appspotmail.com.

https://developers.google.com/appengine/docs/python/mail/sendingmail

2
  • 1
    Whoops! I misunderstood what sending address I was supposed to use for my app. Service Account Name: [email protected] Use this name when interacting with external services on behalf of your application. Thanks for your help!
    – Harrison
    Jul 23, 2012 at 22:16
  • I have tried with all mails they have mentioned, owner mail, gserviceaccount mail, mail account with app name still it is giving as unauthorised sender, thanks Jan 3, 2017 at 4:52
11

First follow these steps

https://cloud.google.com/appengine/docs/python/mail/#who_can_send_mail

Then you need to manually add the sender email in cloud console

How to add an authorized sender

1
  • 1
    This is the best answer, as you have to do both steps to be able to send mail from the server.
    – Pedro
    May 14, 2017 at 10:57
3

You may also have to add the email address you which to send the email from to the App Engine application settings Email API authorized senders.

See https://cloud.google.com/appengine/docs/python/mail/#Python_Sending_mail

2

Add the unauthorized email address as an administrator here: https://console.developers.google.com/project/_/permissions/projectpermissions

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.