views:

35

answers:

2

I have a html form with <textarea name="message"></textarea> and I get the value by message = self.request.get('message').

Then I do mail api

message = mail.EmailMessage(sender="[email protected]", subject="Testing")
message.to = '[email protected]'
message.html = """The Message: %s """ % (message)
message.send()

The problem is I can only see the "The Message:" in my email without the 'message' value, how do I solve the problem?

+3  A: 

You're using the variable name 'message' for both the original text in the textarea, and the email you're sending. Try this:

text = self.request.get('message')
message = mail.EmailMessage(sender="[email protected]", subject="Testing") 
message.to = '[email protected]' 
message.html = """The Message: %s """ % (text) 
message.send()
Saxon Druce
+1  A: 

I'm not familiar with the GAE mail api but you seem to reassign the message variable name to a new item, in this case an object, then you try to make the object the message body. :s

Try something like:

message = self.request.get('message')
mailer = mail.EmailMessage(sender="[email protected]", subject="Testing")
mailer.to = '[email protected]'
mailer.html = """The Message: %s """ % (message)
mailer.send()

In production you would probably also want to do a null check for the message variable's value.

methode