我曾尝试使用flask_mail 通过gmail SMTP 发送电子邮件。我想简单地向主机发送一封包含一些详细信息的电子邮件。
我已经设置了以下设置
app = Flask(__name__)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'fakeemail@gmail.com'
app.config['MAIL_PASSWORD'] = 'fakepassword'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
并写了以下代码发送
def send_email(senders_email, senders_subject, senders_feedback):
print("email " + senders_email)
print("sub " + senders_subject)
print("feed " + senders_feedback)
msg = Message('Feedback from ' + senders_email, sender='fakeemail@gmail.com',
recipients=['fakeemail@gmail.com'])
print("message defined")
msg.body = "Users Subject: " + senders_subject + "\n" + "Users Feedback: " + senders_feedback
print("body set")
mail.send(msg)
print("message sent")
起初我收到了成功的电子邮件,这些电子邮件将特定的电子邮件发送给了我,但现在我在大约 20 或 30 秒后收到了 500 错误
OSError: [Errno 101] Network is unreachable
任何帮助,将不胜感激
函数式编程
相关分类