1.原由:send fail SMTP AUTH extension not supported by server. 使用端口25 和587均失效出现此问题html
首先前往outlook修改设置pop和IMAP开启,容许第三方调用:https://outlook.live.com/owa/?path=/options/popandimappython
【在使用QQ邮箱IOS端的APP添加outlook邮箱时,显示IMAP没有开启】是否意指当您在iOS手机设备中进行配置微软账户至第三方域名邮箱(QQ邮箱)时,git
系统提示Outlook邮箱中的IMAP并未开启?github
查询缘由:版本使用python3.7,官网作出以下变更:server_hostname cannot be an empty string or start with a leading dot.服务器
也就是说如今对于3.7须要对非ssl模式传入smtp server对象传入str模式的host地址再进行server对象建立链接app
或者:eclipse
在github有人曾给出以下修复针对ssl,非sslui
https://github.com/tp4a/teleport/commit/dea9c48d825e7bac5bbc41006bc993713e4b516fspa
尝试修复:服务器不支持SMTP AUTH扩展。3d
最终及解决代码以下:
#!/usr/bin/python3 import os import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header from email.mime.image import MIMEImage def main(): sender='chen1054@outlook.com' receiverList=['chen1054@outlook.com'] user='chen1054@outlook.com' emailPwd='youroutlookpwd'#用户邮箱密码无需开通受权码 smtpServer=r'smtp-mail.outlook.com' commonPort=587 # 25也有效 emailTitle='Hello,World!' htmlPath=r'F:/eclipse/readme/readme_eclipse.html' attachPathList=[r'C:\Users\Administrator\PycharmProjects\Supro\src\logs\Info\20190330.log',r'C:\Users\Administrator\PycharmProjects\Supro\src\logs\Info\testpc.png'] emailChanel(sender,receiverList,user,emailPwd,smtpServer,commonPort,emailTitle,htmlPath,attachPathList) def emailChanel(sender,receiverList,user,emailPwd,smtpServer,commonPort,emailTitle,htmlPath=None,attachPathList=None): multiPart=MIMEMultipart() multiPart['From']=sender multiPart['To']=','.join(receiverList) subject=emailTitle multiPart['Subject']=Header(subject,"utf-8") if os.path.isfile(htmlPath): if os.path.exists(htmlPath): pass else: raise IOError("htmlPath not exist") else: raise IOError("html path is not file..") emailBody=MIMEText(_text=open(htmlPath,'rb').read(),_subtype='html',_charset="utf-8") multiPart.attach(emailBody) if isinstance(attachPathList,list): for attachPath in attachPathList: if os.path.exists(attachPath): pass else: raise IOError("attachPath not exist") else: raise TypeError("expected type is list,but get {}".format(type(attachPathList).__name__)) for attachPath in attachPathList: if os.path.splitext(attachPath)[-1]==".log": attach=MIMEText(open(attachPath, 'rb').read(), 'base64', 'utf-8') attach["Content-Type"] = 'application/octet-stream' attach["Content-Disposition"] = 'attachment; filename="dailyLog.log"' # filename not strict multiPart.attach(attach) if os.path.splitext(attachPath)[-1]==".png": fp = open(attachPath, 'rb') msgImage = MIMEImage(fp.read(),_subtype='octet-stream') fp.close() msgImage.add_header('Content-Disposition', 'attachment', filename="attach.png") multiPart.attach(msgImage) # https://github.com/tp4a/teleport/commit/dea9c48d825e7bac5bbc41006bc993713e4b516f smtp=smtplib.SMTP("{}:{}".format(smtpServer,commonPort)) try: smtp.ehlo() smtp.starttls() smtp.login(user,emailPwd) smtp.sendmail(sender,receiverList,multiPart.as_string()) except smtplib.SMTPException as e: print("send fail",e) else: print("success") finally: try: smtp.quit() except smtplib.SMTPException: print("quit fail") else: print("quit success") if __name__ == '__main__': main()