asp.net Jmail表单提交发送邮件成功例子
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Model;
using BLL;
public partial class Show_Msg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnADD_Click(object sender, EventArgs e)
{
string msgType = this.ddlType.SelectedItem.Value;
string msgContent = this.txtMsgContent.Text;
string tel = this.txtTel.Text;
string msgmail = this.txtMail.Text;
Msg msg = new Msg();
msg.MsgType = msgType;
msg.MsgContent = msgContent;
msg.MsgTel = tel;
msg.MsgMail = msgmail;
if (msgManage.AddMsg(msg))
{
jmail.Message mail = new jmail.Message();
string subject = msgContent.Substring(0, 5) + "...";
string frommail = "111111111@163.com";
string tomail = "2222222@qq.com";
//silent属性:如果设置为true,jmail不会抛出例外错误. jmail. send( () 会根据操作结果返回true或false
mail.Silent = true;
//jmail创建的日志,前提loging属性设置为true
mail.Logging = true;
//字符集,缺省为"us-ascii"
mail.Charset = "gb2312";
mail.AddRecipient(tomail, "", "");
mail.From = frommail;
//发件人邮件用户名
mail.MailServerUserName = "luyangt";
//发件人邮件密码
mail.MailServerPassWord = "why1979524";
//设置邮件标题
mail.Subject = subject;
//邮件内容
mail.Body = "网站有留言:\n" + "留言类别:" + msgType +"\n留言信息:"+ msgContent;
mail.Body += "\n留言人联系方式:\n tel:" + tel + "\n E-Mail: " + msgmail;
mail.Body += "\n详细信息请登录网站了解http://12312321.com";
//jmail发送的方法
if (mail.Send("smtp.163.com", false))
{
Response.Write("<script>alert('提交成功')</script>");
}
else
{
Response.Write("<script>alert('系统忙请重新提交')</script>");
}
mail.Close();
//this.TextBox5.Text = string.Empty;
//Response.Write("<script>alert('提交成功')</script>");
}
else
{
Response.Write("<script>alert('提交失败')</script>");
}
}
}