2013-03-16 172 views
2

我正在開發應用程序,它發送電子郵件。我在Hotmail上創建了帳戶。 這是我的代碼:通過Hotmail發送郵件到Gmail gmail

try 
{ 
    using (var smtpClient = new SmtpClient()) 
    { 
     var mailAddressTo = new MailAddress(emailType.EmailAddress); 
     var mailAddressFrom = new MailAddress("id"); 
     using (var mailMessage = new MailMessage(mailAddressFrom, mailAddressTo)) 
     { 
      smtpClient.Host = "smtp.live.com"; 
      smtpClient.Port = 587; 
      smtpClient.EnableSsl = true; 
      smtpClient.Credentials = new NetworkCredential("[email protected]", "pass"); 
      mailMessage.Subject = emailType.EmailSubject;    
      smtpClient.Send(mailMessage); 
     } 
    } 
} 
catch (Exception ex) 
{} 

但它給了我異常:

Mailbox unavailable. The server response was: 5.3.4 Requested action not taken; We noticed some unusual activity in your Hotmail account. To help protect you, we've temporarily blocked your account.

我不想使用Gmail,因爲它需要的電話號碼。我怎麼用hotmail做到這一點? 謝謝

+0

提供的錯誤消息,顯然看起來就像你不能使用Hotmail – levelnis 2013-03-16 11:40:37

+1

做到這一點我不明白爲什麼這個問題已被標記下來...我有同樣的問題,並幫我解決它。 – Roman 2015-08-03 00:04:44

回答

9

試試這個。它爲我工作。

 SmtpClient SmtpServer = new SmtpClient("smtp.live.com"); 
     var mail = new MailMessage(); 
     mail.From = new MailAddress("[email protected]"); 
     mail.To.Add("ToGmail.com"); 
     mail.Subject = "Your Sub"; 
     mail.IsBodyHtml = true; 
     string htmlBody; 
     htmlBody = "HTML code"; 
     mail.Body = htmlBody; 
     SmtpServer.Port = 587; 
     SmtpServer.UseDefaultCredentials = false; 
     SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "YourPassword"); 
     SmtpServer.EnableSsl = true; 
     SmtpServer.Send(mail); 
+0

謝謝。它的工作。 – JuP 2013-03-16 12:07:05

+0

我使用帳戶[email protected]但我收到錯誤:郵箱不可用。服務器響應是:5.7.3請求的操作中止;用戶未通過身份驗證。我使用live.com登錄,一切正常。 – Kiquenet 2014-01-01 21:07:33