2017-05-23 43 views
1

我能夠通過包我發現叫EAGetMail成功。不幸的是,我很快意識到他們有一個令牌系統,這是一個免費的方法,而且這不是而是C#控制檯應用程序 - 解析Office 365的收件箱

有可供一對夫婦的其他選擇,比如使用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之間看到解決方案。如果任何人有從實際建立連接到從收件箱中拉取消息的輕量級解決方案,那將非常棒!

+1

與Office365沒試過......但你有沒有試過[Exchange Web服務(https://msdn.microsoft.com/en-us/library/office/dd877045(V = exchg 0.140)的.aspx)? –

+1

EWS將與Office 365電子郵件帳戶一起使用。 https://stackoverflow.com/questions/32355440/connection-to-office-365-by-ews-api – Bearcat9425

+0

@ Bearcat9425,我會嘗試這種方式,但希望能看到您的解決方案,如果你有一個方便。 – NoReceipt4Panda

回答

0

我使用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 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); 
     } 
    } 
} 
+0

很高興它爲你工作! – Bearcat9425