2013-03-16 173 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