Python通过网易的SMTP发送邮件

今天用163 smtp发邮件的时候,提示550 User has no permission,看代码是没有问题,搜索后发现是网易邮箱第三方发邮件是需要授权码的,具体是进入邮箱,见上面菜单的设置下面的POP3/SMTP/IMAP开通 POP3/SMTP服务,IMAP/SMTP服务,然后设置客户端授权码,在smtp.login的时候设置成邮箱加授权码发送就可以。具体如下代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Randy'
import smtplib
from smtplib import SMTPException

sender = 'test@163.com'
receivers = ['admin@pythonxyz.com']

SUBJECT = "统计通知服务!"
TEXT = "Pythonxyz通知,具体见后台地址."

message = """\
From: %s
To: %s
Subject: %s
%s
""" % (sender, ", ".join(receivers), SUBJECT, TEXT)

try:
    smtpObj = smtplib.SMTP('smtp.163.com')
    smtpObj.login('test@163.com','授权码')
    smtpObj.sendmail(sender, receivers, message)
    print "Successfully sent email"
except SMTPException as ex:
    print ex
    print "Error: unable to send email"

发邮件的常见错误可见下面的连接: 发邮件的常见错误


相关推荐


评论(0条)

暂时还没有评论,第一个来评论吧!


我要发表看法

引用   粗体   链接   缩进  

最近编辑

热门标签