Search code examples
pythongoogle-app-enginewebapp2

Python GAE Problems Sending Email


I'm trying out GAE and having a little trouble sending email from my application in both development and production. I understand the development server needs a little configuration first, but production should be send email. There are no errors that I can see viewing the console (I start the server via terminal window), and none reported in the production application.

The code:

def contactSend():
message = mail.EmailMessage()
message.sender = "myaddress@gmail.com"
message.to = "myaddress@gmail.com"
message.subject = "Test email from python"
message.body = "This is the test"
message.send()

What I have checked so far: Code appears to be correct. -Sender (and to) address have administrator level permissions of the project. -Project is configured as Python 2.7 (some issues on 2.5 I guess). -My spam folder.

I'm sure I'm likely missing something simple as I'm very new to GAE. Any ideas would be greatly appreciated.

Edit: I've also tried mail.sendmail:

mail.send_mail(sender="myaddress@gmail.com",
          to="myaddress@gmail.com",
          subject="This is the test 1124pm",
          body="TEST!")

No luck there either. Possible that I need to register a domain or set up a Google Apps account maybe?

Edit2 11:52am: I've tried a check_valid_email to be sure and that came back true. I saw the "send_mail_to_admins" function and gave that a shot assuming it might be less restricting and possibly work, but nothing there either.

Edit3: I don't know if it helps but here's the request handler:

class contactSend(webapp2.RequestHandler):
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        contactSend()
        self.response.out.write("sent! ")  

Solution

  • Your code snippets appear to be correct (with the exception of improper indentation of your first function), so I'm going to provide some debugging information to help you solve your problem.

    1. Check the Logs of your application to see if any exceptions are being raised by your code which may prevent things from working as intended.
      https://appengine.google.com/logs?&app_id=YOUR_APP_ID
    2. Check the Quota Details of your application to see if any emails have been sent. https://appengine.google.com/dashboard/quotadetails?&app_id=YOUR_APP_ID
    3. Ensure the sender email address has accepted the App Engine invite and is not listed as "pending" on the Permissions page. https://appengine.google.com/permissions?&app_id=YOUR_APP_ID
    4. Double-check the to and sender email addresses. Copy/paste them and try to send an email to them directly through the email application of your choice.