Post. And I'd recommend doing a redirect (302) after the mail is sent so that if the user accidently presses the refresh button, mail is not resent.
-- Happy Hacking, Gaurav Vaish www.mastergaurav.com On Nov 19, 7:25 am, Zeynel <[email protected]> wrote: > The tutorial > herehttp://code.google.com/appengine/docs/python/mail/sendingmail.html > has POST: > > class InviteFriendHandler(webapp.RequestHandler): > @login_required > def post(self): > to_addr = self.request.get("friend_email") > .... > > But when I tried the same code with POST it did not send any mail. > Then I changed it to GET and it sent the email. Can you explain the > logic behind using GET or POST when sending email. This is the code I > am using: > > class InviteFriendHandler(webapp.RequestHandler): > #...@login_required > # change "def post(self):" of the tutorial to "def get(self):" > def get(self): > confirmation_url = "http://example.com/" > to_addr = self.request.get("friend_email") > > message = mail.EmailMessage() > message.sender = users.get_current_user().email() > message.to = to_addr > # tutorial is missing subject which throws error. > message.subject = "hello" > message.body = "Click on the link %s " % confirmation_url > > message.send() > > The form from which I get "friend_email" is in the MainPage: > > class MainPage(webapp.RequestHandler): > def get(self): > user = users.get_current_user() > greeting = None > if user: > greeting = ("Welcome, %s! (<a href=\"%s\">sign out</a>)" % > (user.nickname(), > users.create_logout_url("/"))) > else: > greeting = ("<a href=\"%s\">Sign in or register</a>" % > users.create_login_url("/")) > > self.response.out.write(""" > <html> > <body> > <form action="/invite" method="get"> > email: <input type="text" name="friend_email" /> > <input type="submit" value="Submit" /> > </form> > </body> > <html>""") > > self.response.out.write(greeting) -- 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.
