日期:2014-05-18 浏览次数:20411 次
static string strHost = String.Empty; static string strAccount = String.Empty; static string strPwd = String.Empty; static string strFrom = String.Empty; /// <summary> /// 发送邮件 /// </summary> /// <param name="to">接收方邮件地址</param> /// <param name="title">邮件标题</param> /// <param name="content">邮件正文内容</param> public static bool sendmail(string to, string title, string content) { strHost = "stmp.XXX.com"; //STMP服务器地址 //此处实际运用中用的是我们公司的邮件服务器(支持stmp) strAccount = "X@XXX.com"; //SMTP服务帐号 strPwd = "123456"; //SMTP服务密码 strFrom = "X@XXX.com"; //发送方邮件地址 SmtpClient _smtpClient = new SmtpClient(); _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式 _smtpClient.Host = strHost; ;//指定SMTP服务器 _smtpClient.Credentials = new System.Net.NetworkCredential(strAccount, strPwd);//用户名和密码 System.Net.Mail.MailMessage _mailMessage = new System.Net.Mail.MailMessage(strFrom, to); _mailMessage.Subject = title;//主题 _mailMessage.Body = content;//内容 _mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码 _mailMessage.IsBodyHtml = true;//设置为HTML格式 _mailMessage.Priority = MailPriority.High;//优先级 try { _smtpClient.Send(_mailMessage); return true; } catch (Exception ex) { return false; } } //提交 protected void btnadd_Click(object sender, ImageClickEventArgs e) { string title = Request.Form["title"].ToString().Trim(); string text = Request.Form["text"].ToString(); if (sendmail("我的邮箱@qq.com", title, text) == true) { base.Response.Write("<script>alert('您的意见已成功反馈,感谢您的支持!');location.href('" +Request.Url + "');</script>"); } else { base.Response.Write("<script>alert('系统繁忙,请稍后再试!');location.href('" + Request.Url + "');</script>"); } }
public bool SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody) { System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);