1、开通QQ邮箱的POP3和SMTP服务

Python SMTP 邮件
标题
2、如下图 获取 授权码

Python SMTP 邮件
标题
3、发送显示效果,我是自己发送给自己 就会有 代发 字样

Python SMTP 邮件
标题


from smtplib import SMTP as smtp
from email.mime.text import MIMEText
from email.header import Header

try:
    LoginUser = '邮箱登陆名称'
    # 注意 邮箱登陆密码 是 开通 pop3和 SMTP服务 的授权码
    LoginPassWord = '授权码'
   # 链接邮箱服务
    s = smtp('smtp.qq.com')
    # 登陆邮箱 有的邮箱 不需要登陆
    s.login(LoginUser,  LoginPassWord)
    # 为服务器设置调试 等级
    s.set_debuglevel(1)
    # 邮箱 主题
    message = MIMEText('Python 邮件发送测试...', 'plain', 'utf-8')
    # 发件人名称: 显示名称
    message['From'] = Header("发送者Python", 'utf-8')  # 发送者
    # 收件人名称: 显示名称
    message['To'] = Header("接收者", 'utf-8')
    # 发送内容
    subject = 'Python SMTP 邮件测试'
    message['Subject'] = Header(subject, 'utf-8')
    # 开始发送  FROM, TO, Msg
    s.sendmail( '发送者@qq.com', '接收者邮箱地址', message.as_string())
    s.quit()
    print('发送成功')
except Exception as e:
    print('出错了')
    print(e)

 

 

 

 

相关文章:

  • 2021-09-10
  • 2021-09-12
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-10
  • 2021-09-23
  • 2022-01-09
  • 2021-10-12
相关资源
相似解决方案