请教:发邮件发送代码有错误,被服务器拒收,我找不到问题出在哪里
def sendfile(filepath):
from_mail=‘**@163.com’
to_mail=‘**@qq.com’
msg=MIMEMultipart()
msg[‘From’]=from_mail
msg[‘To’]=to_mail
msg[‘Subject’]=’subject’
content=MIMEText(open(filepath, ‘r’).read(), ‘base64’, ‘gb2312’)
content[“Content-Type”] = ‘application/octet-stream’
content.add_header(‘content-disposition’,’attachment’,filename=filepath)
msg.attach(content)
server=smtplib.SMTP(‘smtp.163.com’)
server.docmd(‘ehlo’,‘**@163.com’)
server.login(‘@163.com’,’**‘)
server.sendmail(from_mail,to_mail,msg.as_string())
server.quit()
def sendall():
for root, dirs, files in os.walk(‘D:/foolbak/‘):
for one in files:
tempfile=root+’/‘+one
sendfile(tempfile)
time.sleep(30)
推荐文章: