我有 C# 代码来发送邮件。该代码适用于 gmail、yahoo 配置。但是对于hotmail,有时会发送邮件,有时不会发送邮件。我观察到 yahoo 邮件的响应时间比 gmail 更好。但是 hotmail 的响应与 yahoo、gmail 相比非常差。
会是什么原因?如何配置hotmail以获得良好的响应。
这是我发送邮件的代码:
private void button2_Click(object sender, EventArgs e)
{
SmtpClient client = new SmtpClient();
MailMessage message = new MailMessage();
message.To.Add("user_name");
message.From = new MailAddress("user_name");
message.Subject = "Email Confirmation";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.UTF8;
client.Port=587
client.Host="smtp.live.com";
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("user_name", "password");
if (mail_server == "smtp.gmail.com" || mail_server == "smtp.live.com")
{
client.EnableSsl = true;
}
client.UseDefaultCredentials = false;
client.Credentials = nc;
Ping p = new Ping();
bool result = false;
int i = 10;
do
{
PingReply reply = p.Send("smtp.live.com", 587);
if (reply.Status == IPStatus.Success)
{
result = true;
} Thread.Sleep(500);
i--;
} while (result == false && i != 0);
if (result == true)
{
client.Send(message);
MessageBox.Show("Email sent successfully");
}
else
{
MessageBox.Show("Email not sent");
}
}