exchangelib - 自动发现协议中的所有步骤都失败了

Elw*_*iss 7 python exchange-server exchangewebservices office365 exchangelib

我在python中使用exchangelib时遇到问题.我试试这个示例代码:

from exchangelib import DELEGATE, Account, Credentials

creds = Credentials(
    username='xxxx\\username', 
    password="mypassword"
)

account = Account(
    primary_smtp_address='surname.name@xxxx.fr',
    credentials=creds, 
    autodiscover=True, 
    access_type=DELEGATE
)

# Print first 10 inbox messages in reverse order
for item in account.inbox.all().order_by('-datetime_received')[:10]:
    print(item.subject, item.body, item.attachments)

Run Code Online (Sandbox Code Playgroud)

我尝试了不同的用户名但没有任何作用,我总是有相同的错误消息: AutoDiscoverFailed: All steps in the autodiscover protocol failed

顺便说一句,以防万一它可以提供帮助,我试图使用为C#编码的Exchange Web服务,它可以完美地使用这些信用卡,我可以发送邮件:

static void Main(string[] args)
{
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
    // The last parameter is the domain name
    service.Credentials = new WebCredentials("username", "password", "xxxx.lan");
    service.AutodiscoverUrl("surname.name@xxxx.fr", RedirectionUrlValidationCallback);
    EmailMessage email = new EmailMessage(service);
    email.ToRecipients.Add("surname.name@xxxx.fr");
    email.Subject = "salut ";
    email.Body = new MessageBody("corps du message");
    email.Send();
}

private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
    // The default for the validation callback is to reject the URL.
    bool result = false;

    Uri redirectionUri = new Uri(redirectionUrl);

    /* Validate the contents of the redirection URL. In this simple validation
       callback, the redirection URL is considered valid if it is using HTTPS
       to encrypt the authentication credentials. */
    if (redirectionUri.Scheme == "https")
    {
        result = true;
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

提前致谢 !

Elw*_*iss 11

我终于成功完成了这个配置:

from exchangelib import DELEGATE, Account, Credentials, Configuration

creds = Credentials(
    username="domain_name\\username", 
    password="password"
)

config = Configuration(server='mail.solutec.fr', credentials=creds)

account = Account(
    primary_smtp_address="my email address",
    autodiscover=False, 
    config=config,
    access_type=DELEGATE
)
Run Code Online (Sandbox Code Playgroud)

对于那些遇到同样问题的人,可以通过右键单击"计算机"和"属性"找到您的domain_name.例如,用户名和密码是用于连接到公司邮箱的用户名和密码.对于Configuration中的服务器,对我来说,这个工作:"mail.solutec.fr",其中solutec是我公司的名称,fr是法国的名称.

看起来这个自动发现的家伙真的不喜欢我^^

无论如何,谢谢你的帮助,祝你有个美好的一天!

  • requests.exceptions.SSLError:HTTPSConnectionPool(host ='xyz',port = 443):使用url超出最大重试次数:/EWS/Exchange.asmx(由SSLError引起(SSLError("错误握手:错误([('SSL例程') ,'ssl3_get_server_certificate','证书验证失败')])"))) (2认同)