您的位置:首页 > 编程语言

System.Net.Mail 发送邮件代码

2011-11-17 17:52 429 查看
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("111111@qq.com");
msg.From = new System.Net.Mail.MailAddress("111111@qq.com", "zmh886", System.Text.Encoding.UTF8);
msg.Subject = "这是测试邮件";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = "邮件内容";//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;//是否是HTML邮件
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Credentials = new System.Net.NetworkCredential("111111@qq.com", "密码");
client.Host = "smtp.qq.com";
object userState=msg;
try
{
client.Send(msg);
//client.SendAsync(msg, userState); //异步发送
Response.Write("发送成功");
}
catch (System.Net.Mail.SmtpException ex)
{
Response.Write("发送邮件出错!<br>" + ex.Message);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: