发送电子邮件 flask google 应用程序引擎 - 发件人格式无效
Send email flask google app engine - Invalid sender format
我正在尝试在 google 应用引擎上制作一个简单的 Flask 联系表。我对两者都是新手。
我使用了两个链接来帮助我:
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('your@email.com')])
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
您是否遵守他们关于谁可以出现在电子邮件发件人字段中的规则?
The email address of the sender, the From address. The sender address must be one of the following types:
The address of a registered administrator for the application. You can add administrators to an application using the Administration Console.
The address of the user for the current request signed in with a Google Account. You can determine the current user's email address with the Users API. The user's account must be a Gmail account, or be on a domain managed by Google Apps.
Any valid email receiving address for the app (such as xxx@APP-ID.appspotmail.com).
Any valid email receiving address of a domain account, such as support@example.com. Domain accounts are accounts outside of the Google domain with email addresses that do not end in @gmail.com or @APP-ID.appspotmail.com.
https://cloud.google.com/appengine/docs/python/mail/sendingmail
我正在尝试在 google 应用引擎上制作一个简单的 Flask 联系表。我对两者都是新手。
我使用了两个链接来帮助我: 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('your@email.com')])
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
您是否遵守他们关于谁可以出现在电子邮件发件人字段中的规则?
The email address of the sender, the From address. The sender address must be one of the following types:
The address of a registered administrator for the application. You can add administrators to an application using the Administration Console.
The address of the user for the current request signed in with a Google Account. You can determine the current user's email address with the Users API. The user's account must be a Gmail account, or be on a domain managed by Google Apps.
Any valid email receiving address for the app (such as xxx@APP-ID.appspotmail.com).
Any valid email receiving address of a domain account, such as support@example.com. Domain accounts are accounts outside of the Google domain with email addresses that do not end in @gmail.com or @APP-ID.appspotmail.com.
https://cloud.google.com/appengine/docs/python/mail/sendingmail