The tutorial here
http://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)