发件
using System; using System.Text; using System.Net.Mail; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebCms.Web.Admin.Email { public partial class SendMail : Page { public int MailContId; public int ClassId; public int Property; public int State; public string setMail = "loself@nc189.com";//发件人地址 public string setName = "索科特"; //发件人姓名 public string setMailPwd = "qkngndung0208"; //发件人密码 public string MailSubject = "邮件主题"; //邮件主题 public string MContent = "邮件内容"; //邮件内容 public string Host = "smtp.qq.com"; //服务器----imap.qq.com smtp.qq.com public string getMail = "915422989@qq.com"; //收件人地址 protected void btnSave_Click(object sender, EventArgs e) { StringBuilder str = new StringBuilder(); System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.To.Add(getMail); //msg.To.Add("这里填发给地址如WQER@qq.com"); // msg.To.Add("b@b.com"); //可以发送给多人 //msg.CC.Add("c@c.com"); //可以抄送给多人 msg.From = new MailAddress(setMail, setName, System.Text.Encoding.UTF8);/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/ msg.Subject = MailSubject; //邮件主题 msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 msg.Body = MContent; //邮件内容 msg.BodyEncoding = System.Text.Encoding.UTF8; //邮件内容编码 msg.IsBodyHtml = true; //是否是HTML邮件 //msg.Priority = MailPriority.High; //邮件优先级 SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential(setMail, setMailPwd); //发送的邮箱账号密码。这肯定得写你自己的,我用的126 client.Host = Host;//imap.qq.com smtp.qq.com object userState = msg; try { //client.SendAsync(msg, userState); client.Send(msg); Response.Write("<script>alert('发送成功啦')</script>"); } catch (System.Net.Mail.SmtpException ex) { Response.Write("<script>alert('发送失败啦')</script>"); } } } }
"唯有高屋建瓴,方可水到渠成"