登录VDI中的Outlook电子邮件帐户时出错

时间:2018-09-08 10:10:45

标签: python email outlook vdi

当我尝试在VDI中使用python登录我的Outlook电子邮件帐户时,出现了SOCKET错误

代码:

import imaplib, email, os
user     = 'user_name@company.com'
password = 'my_password'
imap_url = 'outlook.office365.com'

def auth(user,password,imap_url):
    con = imaplib.IMAP4_SSL(imap_url)
    con.login(user,password)
    return con

con = auth(user,password,imap_url)

我遇到以下错误

错误:

File "C:\Program Files\Python36\lib\socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11003] getaddrinfo failed

我认为上述错误是由于防火墙引起的。因此,我添加了以下代码以使用代理绕过防火墙

import imaplib, email, os

proxy = 'http://<username>:<password>@proxy.company.com:8080'
os.environ['http_proxy'] = proxy 
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy

user     = 'user_name@company.com'
password = 'my_password'
imap_url = 'outlook.office365.com'

def auth(user,password,imap_url):
    con = imaplib.IMAP4_SSL(imap_url)
    con.login(user,password)
    return con

con = auth(user,password,imap_url)

现在,出现以下错误。有人可以帮我解决这个问题吗?

错误:

  File "C:\Program Files\Python36\lib\socket.py", line 724, in create_connection
    raise err
  File "C:\Program Files\Python36\lib\socket.py", line 713, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

0 个答案:

没有答案