C#控制台应用程序 - 解析Office 365收件箱

问题描述 投票:1回答:1

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

还有其他一些选择,例如使用Outlook Mail REST APIMimeKit,但我对如何实现我的最终结果感到迷茫,因为这些参考中没有“开始完成”代码可用于演示如何解析收件箱一个帐户。

我已经开始在Mimekit的帮助下写这个,但我不确定这是否是正确的方法。

我必须想象它看起来像:

using (var client = new SmtpClient ())
{
    client.Connect("outlook.office365.com", 587);
    client.Authenticate("[email protected]", "mypassword");

    var message = MimeMessage.Load(stream);
}

我不知道如何设置上面提到的stream,我不知道是否可以用MimekitOffice 365这样做。

我愿意在任何其他不通过EAGetMail的方法中找到解决方案。如果有人拥有从实际建立连接到从收件箱中提取消息的轻量级解决方案,那将是非常棒的!

c# parsing office365
1个回答
0
投票

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

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 protected]", "myPassword");
    service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback);

            //creates an object that will represent the desired mailbox
    Mailbox mb = new Mailbox(@"[email protected]");

    //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);
        }
    }
}   
© www.soinside.com 2019 - 2024. All rights reserved.