System.Net.Mail 发送邮件代码
来源:互联网 发布:mac 拼音输入法 编辑:程序博客网 时间:2024/05/20 06:52
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); }