开发者

Google App Engine Python: How to display textarea value in mail

开发者 https://www.devze.com 2023-01-19 08:20 出处:网络
I have a html开发者_如何学Python form with <textarea name=\"message\"></textarea> and I get the value by message= self.request.get(\'message\').

I have a html开发者_如何学Python 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="abc@domain.com", subject="Testing")
message.to = 'bcd@domain.com'
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?


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="abc@domain.com", subject="Testing") 
message.to = 'bcd@domain.com' 
message.html = """The Message: %s """ % (text) 
message.send()


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="abc@domain.com", subject="Testing")
mailer.to = 'bcd@domain.com'
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消