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();
        }

posted on 2007-03-16 12:12  Come on, BABY!  阅读(256)  评论(0)    收藏  举报