【问题标题】:C# Console Application - Parsing Office 365 InboxC# 控制台应用程序 - 解析 Office 365 收件箱
【发布时间】:2017-10-23 10:41:14
【问题描述】:

我能够通过我找到的名为 EAGetMail 的包获得成功。不幸的是,我很快意识到他们有一个令牌系统,这不是免费的方法。

还有其他几个可用的选择,例如使用 Outlook Mail REST APIMimeKit,但我不知道如何实现最终结果,因为这些参考中的任何一个都没有可用的“开始到结束”代码演示如何解析帐户的收件箱。

我在Mimekit 的帮助下开始写这篇文章,但我不确定这是否是正确的方法。

我必须想象它看起来像:

using (var client = new SmtpClient ())
{
    client.Connect("outlook.office365.com", 587);
    client.Authenticate("myemail@office365account.com", "mypassword");

    var message = MimeMessage.Load(stream);
}

我不知道如何设置上面提到的stream,也不知道是否可以使用MimekitOffice 365 进行设置。

我愿意通过EAGetMail的任何其他方法看到解决方案。如果有人有一个轻量级的解决方案,从实际建立连接到从收件箱中提取消息,将会很高兴!

【问题讨论】:

标签: c# parsing office365


【解决方案1】:

我使用EWS(Exchange Web 服务)获得了它。这是我的代码:

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;
}
static void Main(string[] args)
{
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);

    service.Credentials = new WebCredentials("email@myemail.com", "myPassword");
    service.AutodiscoverUrl("email@myemail.com", RedirectionUrlValidationCallback);

            //creates an object that will represent the desired mailbox
    Mailbox mb = new Mailbox(@"email@myemail.com");

    //creates a folder object that will point to inbox folder
    FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);

    //this will bind the mailbox you're looking for using your service instance
    Folder inbox = Folder.Bind(service, fid);

    //load items from mailbox inbox folder
    if (inbox != null)
    {
        FindItemsResults<Item> items = inbox.FindItems(new ItemView(100));

        foreach (var item in items)
        {
            item.Load();
            Console.WriteLine("Subject: " + item.Subject);
        }
    }
}   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 2021-10-31
    • 2015-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多