当前位置:   article > 正文

用Python发送邮件:SMTPAuthenticationError: (550, b’User has no permission’)_smtplib.smtpauthenticationerror: (550, b'user has

smtplib.smtpauthenticationerror: (550, b'user has no permission')

在学习的过程中遇到一些问题:

  1. 未设置客户端授权密码出现的报错: SMTPAuthenticationError: (550, b’User has no permission’)
    该问题是由于未设置授权密码出错,具体解决办法如下:

在这里插入图片描述

改好之后运行以下代码即可:

import smtplib
from email.mime.text import MIMEText
from email.header import Header
 
mail_host="smtp.163.com"  #设置服务器
mail_user="tina_huanghui@163.com"    #用户名
mail_pass="****"   #授权码,注意不是邮箱登录密码,是上述设置的授权密码!!!
sender = 'tina_huanghui@163.com'
receivers = ['425845636@qq.com']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

message = MIMEText('test', 'plain', 'utf-8')
message['From'] = "tina_huanghui@163.com"
message['To'] = "425845636@qq.com"
subject = 'test email'
message['Subject'] = Header(subject, 'utf-8')
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25)  
smtpObj.set_debuglevel(1)
smtpObj.login(mail_user,mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print("邮件发送成功")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

好了,问题解决了!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/602007
推荐阅读
相关标签
  

闽ICP备14008679号