0

我的队友使用上面的 C# (.NET) 代码从他的收件箱中提取电子邮件详细信息。如果您注意到它不需要任何凭证。

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Threading.Tasks; 
    using Microsoft.Exchange.WebServices.Data;    

    namespace ConsoleApplication1 {
        class Program
        {
            static void Main(string[] args)
            {
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

                service.AutodiscoverUrl("FirstName.LastName@company.com", RedirectionUrlValidationCallback);

                if (service != null)
                {
                    FindItemsResults<Item> resultout = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));

                    foreach (Item item in resultout.Items)
                    {
                        EmailMessage message = EmailMessage.Bind(service, item.Id);

                        String subject = message.Subject.ToString();
                        Console.Write(subject);

                        String fromwhom = message.From.Address.ToString();
                        Console.Write(fromwhom);                        
                    }    
                }            
            }

            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;
            }
        } 
    }

我需要在 Python 中执行相同的步骤。即阅读电子邮件详细信息。

我的尝试

from exchangelib import Account, Configuration, Credentials, DELEGATE, IMPERSONATION, NTLM
email = 'FirstName.LastName@company.com'
creds = Credentials(email, "")
account = Account(email, autodiscover=True, credentials = creds)

错误:

AutoDiscoverFailed:自动发现协议中的所有步骤均失败

使用自动发现false

from exchangelib import Account, Configuration, Credentials, DELEGATE, IMPERSONATION, NTLM
email = 'FirstName.LastName@company.com'
creds = Credentials(email, "")
config = Configuration(server = "domain.com", credentials=creds)
account = Account(email, autodiscover=False, config = config)

错误:

用户名或密码错误https;//domain.com/EWS/Exchange.asmx

我可以访问https;//domain.com/EWS/Exchange.asmxvia url,而无需输入任何凭据。

注意:我在 Python 方面相当出色,但不了解 C#。

4

1 回答 1

0

我相信在 Python 中进行身份验证有不同的方法。这是一个

我从事过一个类似的项目,我尝试打印出一封电子邮件 [网络自动化],为此我使用了 selenium 和 webdriver 来访问雅虎邮件。这个项目包括页面检查——另一种方法。代码没有优化,最终输出也不是我想要的,但你至少可以理解这个想法。

祝你好运!

于 2019-09-14T12:15:30.613 回答