thanks Alexander,
the setup and code worked,
one more help, - how do i unescape string in python that was escaped
in javascript and submitted??
I'm submitting html that is escaped from the form - escape(data)
How do I unescape the self.request.get('data') in python and then mail
it ?
javascript:
var data = document.getElementById("message").innerHTML;
document.getElementById("pop").innerHTML = '<form action="/send-email"
method="post">Email: <input name="address" type="text"/><br><input
name="data" type="hidden" value="'+escape(data)+'"><br><input
type="submit" value="Send"/></form>';
-----------------
email.py:
from google.appengine.api import mail
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class SendEmail(webapp.RequestHandler):
def post(self):
user_address = self.request.get('address')
if mail.is_email_valid(user_address):
message = mail.EmailMessage(sender="[email protected]",
subject="test")
message.to = user_address
message.body = """test blah blah"""
message.html = """test blah blah""" + self.request.get('data')
message.send()
self.response.out.write('Email sent')
application = webapp.WSGIApplication([('/send-email', SendEmail)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
--------------------------------
On Dec 16, 12:54 am, Alexander Kojevnikov <[email protected]>
wrote:
> > here is how i have setup the app.yaml,email.py and form.html, let me
> > know whats wrong ??, how should i setup handler foremail.py in
> > app.yaml ??
>
> OK, here's how you can do it.
>
> app.yaml:
> ---------
> handlers:
> - url: /send-email
> script:email.py
> - url: (.*)/
> static_files: static\1/index.html
> upload: static/index.html
> - url: /
> static_dir: static
> ---------
>
> email.py:
> --------
> from google.appengine.api import mail
> from google.appengine.ext import webapp
> from google.appengine.ext.webapp.util import run_wsgi_app
>
> class SendEmail(webapp.RequestHandler):
> def post(self):
> user_address = self.request.get('address')
> if mail.is_email_valid(user_address):
> sender_address = '[email protected]'
> subject = 'test'
> body = """testemail"""
> mail.send_mail(sender_address, user_address, subject, body)
>
> self.redirect('/form.html')
>
> application = webapp.WSGIApplication([('/send-email', SendEmail)],
> debug=True)
>
> def main():
> run_wsgi_app(application)
>
> if __name__ == "__main__":
> main()
> --------
>
> form.html:
> ---------
> <form action="/send-email" method="post">Email: <input name="address"
> type="text"/>
> <input type="submit" value="Send"/>
> </form>
> ---------
>
> I didn't test it, let me know if something doesn't work.
>
> Regarding this line in your original code:
>
> # prompt user to enter a valid address
>
> You have quite a few options, the easiest one is probably to redirect
> to a static page containing an error message and a link back to theemailform.
> Other options will probably involve templates or and/or
> some javascript.
>
> Also note that the sender_address must be the administrator of your
> app or the currently signed in
> user:http://code.google.com/appengine/docs/mail/overview.html
>
> Hope this helps.
>
> --www.muspy.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---