我想在谷歌應用程序引擎上做一個簡單的燒瓶聯繫表格。我對這兩個都很陌生。發送電子郵件燒瓶谷歌應用程序引擎 - 無效的發件人格式
有,我已經習慣了幫我兩個環節: https://cloud.google.com/appengine/docs/python/mail/sendingmail http://www.boxcontrol.net/adding-contact-form-to-your-site-using-flask-and-python3.html#.VWnRUlzBzGc
這是我的代碼:
main.py
from flask import Flask, render_template, request
from google.appengine.api import mail
from forms import ContactForm
app = Flask(__name__)
app.secret_key = 'YourSuperSecreteKey'
@app.route('/')
def hello():
"""Return a friendly HTTP greeting."""
return 'Hello World!'
@app.route('/contact', methods=('GET', 'POST'))
def contact():
form = ContactForm()
if request.method == 'POST':
if form.validate() == False:
return 'Please fill in all fields <p><a href="/contact">Try Again!!!</a></p>'
else:
message = mail.EmailMessage(sender=form.name.data,
subject="Contact")
message.to = form.email.data
message.body = form.message.data
message.send()
return "Successfully sent message!"
elif request.method == 'GET':
return render_template('contact.html', form=form)
if __name__ == '__main__':
app.run()
form.py
from flask_wtf import Form
from wtforms import StringField, TextAreaField, SubmitField, validators
def CheckNameLength(form, field):
if len(field.data) < 4:
raise ValidationError('Name must have more then 3 characters')
class ContactForm(Form):
name = StringField('Your Name:', [validators.DataRequired(), CheckNameLength])
email = StringField('Your e-mail address:', [validators.DataRequired(), validators.Email('[email protected]')])
message = TextAreaField('Your message:', [validators.DataRequired()])
submit = SubmitField('Send Message')
我得到的錯誤是:對不起,意外的錯誤:無效的發件人格式
誰能幫助我理解我在做什麼錯?
Exception on /contact [POST]
Traceback (most recent call last):
File "/base/data/home/apps/s~smart-cove-95709/1.384668257912944999/lib/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/base/data/home/apps/s~smart-cove-95709/1.384668257912944999/lib/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/base/data/home/apps/s~smart-cove-95709/1.384668257912944999/lib/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/base/data/home/apps/s~smart-cove-95709/1.384668257912944999/lib/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/base/data/home/apps/s~smart-cove-95709/1.384668257912944999/lib/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/base/data/home/apps/s~smart-cove-95709/1.384668257912944999/main.py", line 40, in contact
message.send()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py", line 1115, in send
raise ERROR_MAP[e.application_error](e.error_detail)
BadRequestError: Invalid sender format