我在python中使用exchangelib有问题。我尝试下面的示例代码:
from exchangelib import DELEGATE, Account, Credentials
creds = Credentials(
username='xxxx\\username',
password="mypassword"
)
account = Account(
primary_smtp_address='[email protected]',
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)
我尝试使用不同的用户名,但没有任何效果,并且我始终遇到相同的错误消息:
顺便说一句,以防万一它可能会有所帮助,我尝试使用为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("[email protected]", RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("[email protected]");
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;
}
提前致谢 !
最佳答案
我终于成功完成了此配置:
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
)
对于将有相同问题的用户,可以通过右键单击“计算机”和“属性”来找到您的domain_name。
例如,用户名和密码就是您用来连接到公司邮箱的密码。对于Configuration中的服务器,对我而言,这是有效的:“mail.solutec.fr”,其中solutec是我公司的名称,fr在法国。
看起来这个自动发现家伙真的不喜欢我^^
无论如何,感谢您的帮助,祝您有美好的一天!
关于python - exchangelib-自动发现协议(protocol)中的所有步骤均失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46525041/