python flask 发送邮件的配置

from  flask  import  Flask

from flask_mail import Mail, Message

app = Flask(__name__)

app.config["MAIL_SERVER"] = " s m t p .163.com " 代理邮箱服务器的名字 

app.config['MAIL_PORT'] = 465  #端口

app.config['MAIL_USE _  SSL'] = True

app.config['MAIL_USERNAME'] = "good [email protected]" #发送者的邮箱

app.config['MAIL_PASSWORD'] = "  "#授权码  

app.config['MAIL_DEFAULT_SENDER'] =  'Flask Admin '#默认的发送邮件的地址

mail = Mail(app)

@app.route('/')

def index(): 

 return'发送邮件' 

@app.route('/send_mail')

def send_mail(): 

 message = Message('邮件主题', recipients=['[email protected]',])#发送给谁可以给多个邮箱进行发送 message.html="

哈哈

"

mail.send(message)

return '发送中'

if __name__ == '__main__':

app.run(debug=True ,port=5001)

你可能感兴趣的:(python flask 发送邮件的配置)