设为首页收藏本站
查看: 64|回复: 0

[PHP] python收发邮件

[复制链接]

论坛元老

Rank: 6Rank: 6

积分
34274
主题
17031
UID
1347
M币
67
贡献
17176

  • 发表于 2017-5-14 02:44:00 | 显示全部楼层 |阅读模式
    #coding: utf-8
    import smtplib
    from email.mime.text import MIMEText
    from email.header import Header

    sender = '×××@163.com'
    receiver = '×××@qq.com'
    subject = 'python email test2'
    smtpserver = 'smtp.163.com'
    username = '×××'
    password = '×××' # 授权码,不是密码

    msg = MIMEText('你好','text','utf-8')#中文需参数‘utf-8’,单字节字符不需要
    msg['Subject'] = Header(subject, 'utf-8')
    msg["To"]=receiver
    smtp = smtplib.SMTP()
    smtp.connect('smtp.163.com')
    smtp.login(username, password)
    smtp.sendmail(sender, receiver, msg.as_string())
    smtp.quit()
    ------------如果passwd不是授权码的话,报错如下-------------------
    jack@jack-desktop:~/work/script/test$ python testemai.py
    Traceback (most recent call last):
    File "testemai.py", line 19, in  
    smtp.login(username, password)
    File "/home/jack/anaconda/lib/python2.7/smtplib.py", line 622, in login
    raise SMTPAuthenticationError(code, resp)
    smtplib.SMTPAuthenticationError: (535, 'Error: authentication failed')
    jack@jack-desktop:~/work/script/test$ python testemai.py
    Traceback (most recent call last):
    File "testemai.py", line 19, in  
    smtp.login(username, password)
    File "/home/jack/anaconda/lib/python2.7/smtplib.py", line 622, in login
    raise SMTPAuthenticationError(code, resp)
    smtplib.SMTPAuthenticationError: (535, 'Error: authentication failed')
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    在我站开通SVIP可同时获得17个站点VIP资源 立即登录 立即注册
    快速回复 返回顶部 返回列表