flask-mail

flask 发邮件

  • 安装 flask-mail
	pip install flask-mail	
  • 配置信息
  # 邮箱设置
  MAIL_SERVER = "smtp.qq.com"
  MAIL_PORT = "587"
  MAIL_USE_TLS = True
  MAIL_USERNAME = "[email protected]"
  MAIL_PASSWORD = "mssmnlfqtykfbbee" #生成的授权码
  MAIL_DEFAULT_SENDER = "[email protected]"
  MAIL_HEADER = '鸭梨视频信息验证通知'
  MAIL_BODY = '验证码为:{}, 有效期为45分钟。'
  • 导入模块
  from flask_mail import Mail,Message
  • 实例化
  mail = Mail()
  • 代码块
  # 生成发送信息
  message = Message(subject='主题', recipients=['收件人邮箱'], body='主体')
  # 发送邮件
  mail.send(message) 
  • 参数配置
参数名称 类型 说明
subject string 主题
recipients list 收件人邮箱
body string 主体文本
html string 主体文本
attachments list 附件

你可能感兴趣的:(flask专题)