Heim > Fragen und Antworten > Hauptteil
贴出部分代码:
app.config['MAIL_SERVER'] = 'smtp.163.com'
app.config['MAIL_PORT'] = '994'
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = '我的手机@163.com'
app.config['MAIL_PASSWORD'] = '我的登录密码'
msg = Message('test', sender='我的手机@163.com', recipients=['xxxxxxx@qq.com'])
msg.body = '文本 body'
msg.html = '<b>HTML</b> body'
with app.app_context():
mail.send(mail)
运行后出现以下错误:
从上面错误看起来好像是send的错误,而且错误原因应该是没有实现的命令,但是这不是flask-mail的写法吗?smtp用的是网易邮箱,按照它所说的去配置,应该是没有问题才对的。。。
巴扎黑2017-04-17 17:37:15
以下是发送邮件例子
from flask import Flask
from flask.ext.mail import Mail, Message
app=Flask(__name__)
app.config.update(
MAIL_USE_SSL= True,
MAIL_USE_TLS=True,
MAIL_SERVER='smtp.163.com',
MAIL_PORT=465,
MAIL_USERNAME='your_count@163.com',
MAIL_PASSWORD='your_password'
)
mail=Mail(app)
@app.route("/")
def index():
msg = Message(
'Hello',
sender='sender@163.com',
recipients=
['receiver@qq.com'])
msg.body = "This is the email body"
mail.send(msg)
return "Sent"
if __name__ == "__main__":
app.run(port=8888)