ASP.NET2.0发送邮件实例

以前写过1.1的代码,那是用System.web.mail,可是以前的写法在2005里面会警告了。不爽,改成2.0的写法,需要using System.Net.Mail。代码如下:

            System.Net.Mail.MailMessage mailObj = new System.Net.Mail.MailMessage();
            mailObj.IsBodyHtml = true;
            mailObj.Subject = "Test ASP.Net2.0 Mail";
            mailObj.Body = "You did a good job.";
            mailObj.To.Add("[email protected]");
            System.Net.Mail.SmtpClient SmtpMail = new SmtpClient("smtp.sina.com.cn");
            mailObj.From = new MailAddress("[email protected]", "Catvi", System.Text.Encoding.UTF8);
            SmtpMail.Credentials = new System.Net.NetworkCredential("[email protected]", "××××××");
            SmtpMail.Send(mailObj);

×××××× 是你的账户密码,对应修改。

你可能感兴趣的:(asp.net)