我有一个简单的自动电子邮件代码,它一直工作得很好。而在 Mac OS 系统升级后,它停止工作,并且每次错误显示代号或 servname 提供或未知。有人可以帮助我吗?我的代码如下
today = date.today().strftime("%m%d%Y")
outputpath = os.path.expanduser('~/Downloads')
Filename1 = 'dummy attachement 1'
Filename2 = 'dummy attachment 2'
_user = "***"
_pwd = "***"
_to = "dummy@gmail.com"
msg = MIMEMultipart()
msg["Subject"] = "Dummy email"
msg["From"] = _user
msg["To"] = _to
part = MIMEText("Test dummy email")
msg.attach(part)
part1 = MIMEApplication(open(Filename1,'rb').read())
part1.add_header('Content-Disposition', 'attachment', filename=Filename1)
#part2 = MIMEApplication(open(Filename2,'rb').read())
#part2.add_header('Content-Disposition', 'image', filename=Filename2)
#msg.attach(part2)
msg.attach(part1)
s = smtplib.SMTP("smtp.gmail.com", timeout=25)
s.set_debuglevel(1)
s.ehlo()
s.starttls()
s.login(_user, _pwd)
s.sendmail(_user, _to.split(','), msg.as_string())
s.close()