flask 框架 用126邮箱发邮件

app.config['SECRET_KEY'] = "you dont kown"
app.config['MAIL_SERVER'] = 'smtp.126.com'
app.config['MAIL_PORT'] = 25
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = False
app.config['MAIL_USERNAME'] = '[email protected]'
app.config['MAIL_PASSWORD'] = 'xxxx'

 $ python hello.py shell 

>>> from flask.ext.mail import Message

>>>  from app  import mail
>>> 
>>> msg  = Message( 'test subject' , sender  = '[email protected]' , recipients  = ["[email protected]"] )
>>> msg.body  = 'text body'
>>> msg.html  = '<b>测试邮件</b> '

>>> mail.send(msg)

就OK了

你可能感兴趣的:(python,import,126邮箱)