2017-01-24 7 views
0

私は電子メールを送信して電子メールを読むことができる小さなプログラムを作っています。私は現在電子メールを送信できますが、.Net.Mailを使用して受信トレイにアクセスする方法がわかりません。これを行う方法はありますか?あなたはSMTPでメールを取得することはできませんすべての電子メールを受信ボックスで取得する.Net.Mail C#

try 
{ 
    SmtpClient mySmtpClient = new SmtpClient("smtp.live.com"); 

    // set smtp-client with basicAuthentication 
    mySmtpClient.UseDefaultCredentials = false; 
    System.Net.NetworkCredential basicAuthenticationInfo = new 
     System.Net.NetworkCredential("[email protected]", "password"); 
    mySmtpClient.Credentials = basicAuthenticationInfo; 
    mySmtpClient.EnableSsl = true; 

    // add from,to mailaddresses 
    MailAddress from = new MailAddress("[email protected]"); 
    MailAddress to = new MailAddress("[email protected]"); 
    MailMessage myMail = new System.Net.Mail.MailMessage(from, to); 
    MailMessage msg; 

    // set subject and encoding 
    myMail.Subject = "Test message"; 
    myMail.SubjectEncoding = System.Text.Encoding.UTF8; 

    // set body-message and encoding 
    myMail.Body = "<b>Test Mail</b><br>using <b>HTML</b>."; 
    myMail.BodyEncoding = System.Text.Encoding.UTF8; 
    // text or html 
    myMail.IsBodyHtml = true; 

    mySmtpClient.Send(myMail); 
} 

catch (SmtpException ex) 
{ 
    throw new ApplicationException 
     ("SmtpException has occured: " + ex.Message); 
} 
+2

はあなたを持っていますそれをテストしましたか?どうした? –

+0

Microsoftメールアカウント用に保存されているメールフォルダにアクセスする場合は、REST APIを検討してください。@ https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations- POPは切断されませんそれ。 –

+0

これはフレームワークのSystem.Net.Mailでは不可能です。 IMAPやPOP3をサポートしている[MailKit](https://github.com/jstedfast/MailKit)のようなライブラリが必要です。 –

答えて

0

を休閑として

私のコードです。あなたはここに行く

は、詳細情報についてはhttps://github.com/andyedinborough/aenetmail AEMail

のようなライブラリを使用することを検討してIMAPを使用する必要があります。 Accessing Imap in C#

+1

またPOP3もあります –

+0

@PeterRitchie - そうですが、もう誰がそれを使いたいのですか? –

+0

@ rory.ap通常、いくつかのメールプロバイダとの選択についてはありません:( –

-3

はそれはのクラスOpenPop

[http://hpop.sourceforge.net/][1] 

を試してみてくださいドキュメント

+1

これは質問の下のコメントです。 –

関連する問題