![](/img/trans.png)
[英]SCAPY send packet error OSError: [Errno 97] Address family not supported by protocol
[英]Unable to send email from Python due to Address Family not supported Error
尝试从python发送自动电子邮件时,我遇到了错误。
我收到的错误是“ [Errno 97]协议不支持地址族”
# import necessary packages
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
# create message object instance
msg = MIMEMultipart()
password = "password"
msg['From'] = "risk@gmail.com"
msg['To'] = "game@gmail.com"
msg['Subject'] = "Photos"
# attach image to message body
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
# Login Credentials for sending the mail
server.login(msg['From'], password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
我该如何解决此问题。 任何帮助表示赞赏。
我不确定您是否已解决此问题,因此我正在发布对我有用的代码。
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
import smtplib
msg = MIMEMultipart()
password = "password"
msg['From'] = "risk@gmail.com"
msg['To'] = "game@gmail.com"
msg['Subject'] = "Photos"
text = "Here are the photos.\nCheers,\nLife is complex"
msg_text = MIMEText(text, 'plain')
msg.attach (msg_text)
fp = open('image.png', 'rb')
img = MIMEImage(fp.read())
fp.close()
msg.attach(img)
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
# Login Credentials for sending the mail
server.login(msg['From'], password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
顺便说一句,您是否启用了Gmail安全设置,该设置允许“较少的安全应用程序访问”您的Gmail帐户?此设置允许您的python脚本与您的帐户进行交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.