Python smtplib 的发送间断性失败

Python smtplib 的发送间断性失败,第1张

Python smtplib 的发送间断性失败,第2张

使用 163、outlook 总是显示 554, b'DT:SPM 163 smtp9,说是系统判断我是垃圾邮件,可是我只是发了'hello'而已

#!/usr/bin/env python3
#coding: utf-8
# coding: utf-8
import smtplib
import mimetypes
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.header import Header
import email


#列表类
class LS:
mail_address=[
"linhanqiu1123@163.com";
]
#配置类
class Cfg:
mail_config = {
"sender":"workinform@163.com",
"receiver":["linhanqiu1123@163.com"],
"username":"workinform@163.com",
"password":"linhanqiu1123",
#smtp 服务器
"smtpserver":"smtp.163.com"
}
@staticmethod
def insert_md():
global mail_config
for i in LS.mail_address:
mail_config["receiver"].append(i)

sys_config = {
#图片地址
"path": "/home/linhanqiu/img/1.jpg"
}

#内容类
class Content:
def __init__(self,id=None,word="hello",subject=u"hello"):
self.id = id
self.word = word
self.subject = subject
self.html = "<p1></p1>"
#内容格式,其他格式还在添加
def text(self):
msgRoot = MIMEMultipart("related")
msgRoot['Subject'] = Header(self.subject, 'utf-8')
msgRoot['From'] = ','utf-8')">Header('爬虫任务情况<workinform@163.com>','utf-8')
msgRoot['To'] = "linhanqiu1123@163.com";
msgRoot.preamble = 'This is a multi-part message in MIME format.'
#设置转化部分
# msgAlternative = MIMEMultipart("alternative")
# msgRoot.attach(msgAlternative)
# 添加纯文本信息,(添加模板)
# msgText = MIMEText(self.word,'plain','utf-8')
# msgAlternative.attach(msgText)
# 设定 html 信息,(添加模板)
# msgHtml = MIMEText(self.html,'html','utf-8')
# msgRoot.attach(msgHtml)
# 设置图片信息,( matplotlib 画图)
# fp = open(Cfg.sys_config["path"], 'rb')
# msgImage = MIMEImage(fp.read())
# fp.close()
# msgImage.add_header('Content-ID', '<image1>')
# msgRoot.attach(msgImage)
return msgRoot

#邮件基类
class Mail:
def __init__(self):
self.cfg = Cfg.mail_config
self.server = self.cfg["smtpserver"]
self.sender = self.cfg["sender"]
self.receiver = self.cfg["receiver"]
self.username = self.cfg["username"]
self.password = self.cfg["password"]
def login(self):
s = smtplib.SMTP()
s.connect(self.server)
s.login(self.username,self.password)
#调式过程
s.set_debuglevel(1)

s.ehlo("begin connect")

# s.starttls()
return s
def send(self):
s = self.login()
#创建内容
m = Content().text()
try:
s.sendmail(self.sender,self.receiver,m.as_string())
print("已发送")
except smtplib.SMTPRecipientsRefused:
print('Recipient refused')
except smtplib.SMTPAuthenticati onError:
print('Auth error')
except smtplib.SMTPSenderRefused:
print('Sender refused')
# except smtplib.SMTPException as e:
# print(e.message)
s.quit()
def __call__(self, *args, **kwargs):
return self.send()

#商道邮件子类
#娱道邮件子类
if __name__=="__main__":
mail = Mail()
mail() ----------------------- 以下是精选回复-----------------------

答:这个问题比较复杂,我遇到过。但是不是代码的问题,经过反复的测试。
可能是如下的情况
http://blog.csdn.net/sinat_21302587/article/details/69388526
希望能帮到你
答:最好邮件内容齐全比如主题之类,现在反垃圾邮件越来越厉害了

DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
网站模板库 » Python smtplib 的发送间断性失败

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情