先上代码
protected void send_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]", "天行健", System.Text.Encoding.UTF8);//必须是提供smtp服务的邮件服务器
message.To.Add(new MailAddress("[email protected]"));
message.Subject = "测试邮件";
message.Body = "邮件发送测试";
message.IsBodyHtml = false;
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Priority = MailPriority.High;
SmtpClient client = new SmtpClient("smtp.sina.com", 25); // 587;//Gmail使用的端口
client.Credentials = new System.Net.NetworkCredential("[email protected]", "*****"); //这里是申请的邮箱和密码
client.EnableSsl = true; //必须经过ssl加密
try
{
client.Send(message);
Response.Write("邮件已经成功发送到" + message.To.ToString() + "<br>");
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in RetryIfBusy(): {0}",
ex.ToString());
}
}
sina和qq邮箱里SMTP服务都已开启,请高人帮我看看啊。
protected void send_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]", "天行健", System.Text.Encoding.UTF8);//必须是提供smtp服务的邮件服务器
message.To.Add(new MailAddress("[email protected]"));
message.Subject = "测试邮件";
message.Body = "邮件发送测试";
message.IsBodyHtml = false;
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Priority = MailPriority.High;
SmtpClient client = new SmtpClient("smtp.sina.com", 25); // 587;//Gmail使用的端口
client.Credentials = new System.Net.NetworkCredential("[email protected]", "*****"); //这里是申请的邮箱和密码
client.EnableSsl = true; //必须经过ssl加密
try
{
client.Send(message);
Response.Write("邮件已经成功发送到" + message.To.ToString() + "<br>");
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in RetryIfBusy(): {0}",
ex.ToString());
}
}
sina和qq邮箱里SMTP服务都已开启,请高人帮我看看啊。
我后来改用Gmail能实现发送邮件的功能