【发布时间】:2021-10-05 03:34:19
【问题描述】:
尝试在 python 中创建邮件发件人,该脚本可以在我的个人笔记本电脑上运行,但是当我在我的工作笔记本电脑上运行它时(我是最近的实习生),我认为代理妨碍了与gmail smtp 服务器
错误如下:
File "D:\ocm-hours-report-automation\mail-manager\src\python\mail-sender.py", line 44, in <module>
session = smtplib.SMTP('smtp.gmail.com', 587) #use gmail with port
File "C:\Users\myuser\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 312, in _get_socket
return socket.create_connection((host, port), timeout,
File "C:\Users\myuser\AppData\Local\Programs\Python\Python39\lib\socket.py", line 822, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Users\myuser\AppData\Local\Programs\Python\Python39\lib\socket.py", line 953, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
代码是:
#The mail addresses and password
sender_address = 'email1@gmail.com'
sender_pass = 'password'
receiver_address = 'email2@gmail.com'
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Subject'] = 'A test mail sent by Python. It has an attachment.' #The subject line
#The body and the attachments for the mail
message.attach(MIMEText(mail_content, 'plain'))
#Create SMTP session for sending the mail
session = smtplib.SMTP('smtp.gmail.com', 587) #use gmail with port
session.starttls() #enable security
session.login(sender_address, sender_pass) #login with mail_id and password
text = message.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
print('Mail Sent')
任何想法我实际上可以做什么?尝试强制 socks.setdefaultproxy 但它说 socks 导入不可用
谢谢!
【问题讨论】:
标签: python email proxy smtp socks