3

我正在开发发送电子邮件的应用程序。我已经在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做到这一点?谢谢

4

1 回答 1

10

试试这个,它对我有用。

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);
于 2013-03-16T11:49:00.580 回答