smtplib,发送邮件时的bug

发布时间:2020-06-24 13:10:53 作者:田头草
来源:网络 阅读:356

import os
import smtplib

from email.mime.text import MIMEText

def send_mail(receiver):

mail_server = 'smtp.163.com'
sender_useranme = os.getenv('MAIL_USERNAME')
sender_password = os.getenv('MAIL_PASSWORD')

content = '<a href="www.baidu.com">点击完成验证</a>'
message = MIMEText(content, 'html')
message['Subject'] = '用户激活'
message['From'] = sender_useranme

mail = smtplib.SMTP(mail_server)
mail.login(sender_useranme, sender_password)
mail.sendmail(sender_useranme, receiver, message)
mail.quit()

bug : TypeError: expected string or bytes-like object
需要将message对象格式化字符串就OK了

mail.sendmail(sender_useranme, receiver, message.as_string())

有时候服务器会把你发送的邮件当成垃圾邮件处理,当检查完代码都对的时候改一下message['Subject'] = '用户激活'这个的内容试试。

推荐阅读:
  1. html5 canvas 画图时的bug
  2. Python如何基于smtplib协议实现发送邮件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python smtplib 邮件发送

上一篇:java判断文件是否存在的方法

下一篇:java下载文件出现乱码怎么解决

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》