简体   繁体   English

发送电子邮件烧瓶Google App引擎-无效的发件人格式

[英]Send email flask google app engine - Invalid sender format

I'm trying to make a simple flask contact form on google app engine. 我正在尝试在Google App Engine上制作一个简单的烧瓶联系表。 I'm new to both. 我都是新来的。

There are two links which I have used to help me: 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 我使用了两个链接来帮助我: https : //cloud.google.com/appengine/docs/python/mail/sendingmail http://www.boxcontrol.net/adding-contact-form-to-your -site-使用瓶和- python3.html#.VWn​​RUlzBzGc

This is my code: 这是我的代码:

main.py 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 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')

The error I get is: Sorry, unexpected error: Invalid sender format 我收到的错误是: 对不起,意外错误:无效的发件人格式

Can anyone help me understand what I'm doing wrong? 谁能帮助我了解我在做什么错?


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

Are you following the rules they have for who is allowed to be in the from field of the emails? 您是否遵循他们在电子邮件的“发件人”字段中允许谁担任谁的规则?

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. 使用Google帐户登录的当前请求的用户地址。 You can determine the current user's email address with the Users API. 您可以使用Users API确定当前用户的电子邮件地址。 The user's account must be a Gmail account, or be on a domain managed by Google Apps. 该用户的帐户必须是Gmail帐户,或者位于由Google Apps管理的域上。

  • Any valid email receiving address for the app (such as xxx@APP-ID.appspotmail.com). 该应用程序的任何有效电子邮件接收地址(例如xxx@APP-ID.appspotmail.com)。

  • Any valid email receiving address of a domain account, such as support@example.com. 域帐户的任何有效电子邮件接收地址,例如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. 域帐户是Google域之外的帐户,其电子邮件地址不以@ gmail.com或@ APP-ID.appspotmail.com结尾。

https://cloud.google.com/appengine/docs/python/mail/sendingmail https://cloud.google.com/appengine/docs/python/mail/sendingmail

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM