我希望我的 Python 脚本在出现任何异常时向我发送邮件。我尝试了一些与我发现的 SMTP 相关的代码,但不幸的是它没有执行并显示错误。请帮我找出主要问题。
SMTP 代码:
import smtplib
import string
SERVER = 'localhost'
SUBJECT = "Test email from Python"
TO = "abc.def@defghij.com"
FROM = "python@mydomain.com"
text = "Sample of mail"
BODY = string.join(("From: %s" % FROM,"To: %s" % TO,"Subject: %s" %SUBJECT ,"",text), "\r\n")
server = smtplib.SMTP(SERVER) #Here in this line it showing error
server.sendmail(FROM,TO,BODY)
server.quit()
** 错误消息*服务器 = smtplib.SMTP(SERVER)
socket.error: (10047, '协议族不支持地址族:参见http://wiki.python.org/jython/NewSocketModule#IPV6addresssupport ')