For a long time, I have been trying to send email with ASP.NET2.0, but every time I failed. Until yesterday, I happen to find that I always run my application on the computer in my commpany and for the security reason, the SMTP port 25 has been shut down by my commpany's firewall. That's why I cannot send email.
This morning, I have tested the application in my school's lab and it works perfectly! The following is my code
string bodyMessage;
bodyMessage =messageBody.Text ;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("jng_xiao@163.com", receive.Text);
message.Subject =Subject.Text;
message.Body = bodyMessage.Replace(System.Environment.NewLine, "<br>");
message.IsBodyHtml = true;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.163.com");
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("jng_xiao", "mypassword");
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
try
{
client.Send(message);
information.Text = "The email has been send successfully!";
}
catch (Exception ex)
{
information.Text = ex.ToString();
}
浙公网安备 33010602011771号