[英]How to verify sender of incoming email address in Google App Engine?
[英]Send email flask google app engine - Invalid sender format
我正在嘗試在Google App Engine上制作一個簡單的燒瓶聯系表。 我都是新來的。
我使用了兩個鏈接來幫助我: https : //cloud.google.com/appengine/docs/python/mail/sendingmail http://www.boxcontrol.net/adding-contact-form-to-your -site-使用瓶和- 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
您是否遵循他們在電子郵件的“發件人”字段中允許誰擔任誰的規則?
發件人的電子郵件地址,發件人地址。 發件人地址必須是以下類型之一:
該應用程序的注冊管理員的地址。 您可以使用管理控制台將管理員添加到應用程序中。
使用Google帳戶登錄的當前請求的用戶地址。 您可以使用Users API確定當前用戶的電子郵件地址。 該用戶的帳戶必須是Gmail帳戶,或者位於由Google Apps管理的域上。
該應用程序的任何有效電子郵件接收地址(例如xxx@APP-ID.appspotmail.com)。
- 域帳戶的任何有效電子郵件接收地址,例如support@example.com。 域帳戶是Google域之外的帳戶,其電子郵件地址不以@ gmail.com或@ APP-ID.appspotmail.com結尾。
https://cloud.google.com/appengine/docs/python/mail/sendingmail
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.