1

I'm having a problem with sending an email through Google App Engine with Python. I have a website running on a different host which contains a form posting to a Python script in GAE. The script works fine, but fails if I add the "send mail" function in my Python script. I've added:

    self.response.headers['Access-Control-Allow-Origin']='*'

But I still get the error:

XMLHttpRequest cannot load http://www.summit-tech-help.appspot.com/. Origin http://summittechhelp.x10.mx is not allowed by Access-Control-Allow-Origin. 

Here's my Python script.

import cgi,webapp2
from google.appengine.api import mail

class ProblemRedirect(webapp2.RequestHandler):

    def post(self):
        self.response.headers['Access-Control-Allow-Origin']='*'
        problem_text = (cgi.escape(self.request.get('problem_text')))
        student_name =(cgi.escape(self.request.get('student_name')))
        student_email =(cgi.escape(self.request.get('student_email')))
        sender_address= "Summit Tech Help <techhelpsummit@gmail.com>"
        subject = "New Support Ticket!"
        body= "test."
        mail.send_mail(sender_address,sender_address,subject,body)




application = webapp2.WSGIApplication([
    ('/', ProblemRedirect),
], debug=True)

The commented line is what is causing the error. Any help would be appreciated! Thanks!

~Carpetfizz

I also tried adding:

http_headers:
    Access-Control-Allow-Origin: "*"

to my app.yaml file, but I keep getting the error:

Error parsing yaml file:
Unexpected attribute "http_headers" for mapping type script.
  in "/Users/ajay/summit-tech-help/app.yaml", line 13, column 1
Carpetfizz
  • 8,707
  • 22
  • 85
  • 146
  • 1
    Are you posting to this page via javascript? Is techhelpsummit@gmail.com an admin on your apppengine site(it needs to be if you want to send mail from that account). You should also be returning something from this method. – Rob Curtis Sep 20 '13 at 06:44
  • @RobCurtis, yes I'm sending it from the admin account. How do I return something? Does that affect the rest of the code? – Carpetfizz Sep 20 '13 at 14:46
  • The return doesn't matter. I think it'll return status 200 anyway. However, have a look at this question: http://stackoverflow.com/questions/298745/how-do-i-send-a-cross-domain-post-request-via-javascript – Rob Curtis Sep 20 '13 at 15:02
  • are you loading the correct path? The URL http://www.summit-tech-help.appspot.com/ is 404 not found while I attempted to check for the headers returned – user7180 Sep 21 '13 at 01:58
  • Sorry, I disabled it temporarily. I'm using `http://s-t-h-c.appspot.com/`. I'm simply linking my form to this, is that how it is supposed to work? The script is still the same. – Carpetfizz Sep 21 '13 at 02:21

1 Answers1

0

Try also adding the line:

self.response.headers['Access-Control-Allow-Methods'] = 'POST'

Directly in code, not in the app.yaml.

William Gaul
  • 3,181
  • 2
  • 15
  • 21