通过Hotmail发送电子邮件到Gmail

时间:2013-03-16 11:38:07

标签: c#

我正在处理发送电子邮件的应用。我在hotmail上创建了帐户。 这是我的代码:

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("id@hotmail.com", "pass");
            mailMessage.Subject = emailType.EmailSubject;               
            smtpClient.Send(mailMessage);
        }
    }
}
catch (Exception ex)
{}

但它给了我例外:

  

邮箱不可用。服务器响应为:5.3.4未采取请求的操作;我们注意到您的Hotmail帐户中存在一些异常活动。为帮助保护您,我们暂时阻止了您的帐户。

我不想使用Gmail,因为它需要电话号码。我怎么能用hotmail做到这一点? 感谢

1 个答案:

答案 0 :(得分:9)

试试这个。它为我工作。

        SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
        var mail = new MailMessage();
        mail.From = new MailAddress("email@hotmail.com");
        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@hotmail.com", "YourPassword");
        SmtpServer.EnableSsl = true;
        SmtpServer.Send(mail);