IMAP et Csharp
De Banane Atomic
Aller à la navigationAller à la recherche
Bibliothèque AE.NET.Mail
// Connect to the IMAP server. The 'true' parameter specifies to use SSL // which is important (for Gmail at least) ImapClient ic = new ImapClient("imap.gmail.com", "compte@gmail.com", "password", ImapClient.AuthMethods.Login, 993, true); // si l'erreur suivante apparait c'est que les certificats n'ont pas été installés // System.IO.IOException: The authentication or decryption has failed. // ---> System.Exception: Invalid certificate received from server. // sslStream.AuthenticateAsClient(hostname); // Select a mailbox. Case-insensitive ic.SelectMailbox("INBOX"); Lazy<MailMessage>[] unseenEmails = ic.SearchMessages(SearchCondition.Unseen(), false, false); foreach (var lazyEmail in unseenEmails) { var email = lazyEmail.Value; Console.WriteLine ("De: " + email.From.Address); Console.WriteLine ("Sujet: " + email.Subject); Console.WriteLine ("Message: " + email.Body); } // Probably wiser to use a using statement ic.Dispose(); |