2017-05-23 6 views
1

Ich konnte über ein Paket namens EAGetMail erfolgreich sein. Leider merkte ich bald danach, dass sie ein Token-System haben und das ist nicht ein freier Ansatz.C# -Konsolenanwendung - Office 365-Posteingang analysieren

Es gibt ein paar andere Auswahlmöglichkeiten, wie Outlook Mail REST API und MimeKit, aber ich bin verloren auf, wie man mein Endergebnis erreicht, weil kein "Anfang bis Ende" Code auf jeder dieser Referenzen verfügbar ist, die zeigen, wie Analysieren eines Posteingangs für ein Konto.

Ich habe begonnen, dies mit Hilfe von Mimekit zu schreiben, aber bin mir nicht sicher, ob dies der richtige Weg überhaupt ist.

Ich muß sich vorstellen, es sieht so etwas wie:

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

    var message = MimeMessage.Load(stream); 
} 

Ich weiß nicht, wie die stream Setup oben erwähnt, und ich weiß nicht, ob es möglich ist, diese mit Mimekit und Office 365 zu tun.

Ich bin offen dafür, eine Lösung dafür in jedem anderen Ansatz zu sehen, der nicht durch EAGetMail ist. Wenn jemand eine leichtgewichtige Lösung hat, die vom tatsächlichen Herstellen einer Verbindung bis zum Ziehen von Nachrichten aus dem Posteingang reicht, wäre es schön zu sehen!

+1

Nicht mit Office365 versucht ... Aber haben Sie versucht, [Exchange Web Services] (https://msdn.microsoft.com/en-us/library/office/dd877045 (v = EXCHG .140) .aspx)? –

+1

EWS funktioniert mit einem Office 365-E-Mail-Konto. https://stackoverflow.com/questions/32355440/connection-to-office-365-by-ews-api – Bearcat9425

+0

@ Bearcat9425, werde ich es auf diese Weise versuchen, aber würde gerne Ihre Lösung sehen, wenn Sie eine handliche haben. – NoReceipt4Panda

Antwort

0

Ich habe es mit EWS (Exchange Web Services). Hier ist mein Code:

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

Froh, dass es für dich funktioniert hat! – Bearcat9425