Asp.Net下jmail的使用
代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class mailTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string bodystr = "";
bodystr = "一封测试邮件";
jmail.Message jmail = new jmail.Message();
//DateTime t = DateTime.Now;
string subject = "一封测试邮件";
string fromemail = "12345@qq.com";
string toEmail = "ysclc@163.com";
//silent属性:如果设置为true,jmail不会抛出例外错误. jmail. send( () 会根据操作结果返回true或false
jmail.Silent = true;
//jmail创建的日志,前提loging属性设置为true
jmail.Logging = true;
//字符集,缺省为"us-ascii"
jmail.Charset = "gb2312";
//信件的contentype. 缺省是"text/plain") : 字符串如果你以html格式发送邮件, 改为"text/html"即可。
jmail.ContentType = "text/html";
//添加收件人
jmail.AddRecipient(toEmail, "", "");
jmail.From = fromemail;
//发件人邮件用户名
jmail.MailServerUserName = "12345";
//发件人邮件密码
jmail.MailServerPassWord = "password";//qq号密码
//设置邮件标题
jmail.Subject = subject;
//邮件添加附件,(多附件的话,可以再加一条jmail.addattachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的jmail.contenttype="text/html";删掉。否则会在邮件里出现乱码。
//jmail.addattachment( "c:\\test.jpg",true,null);
//邮件内容
jmail.Body = bodystr;
//jmail发送的方法
if (jmail.Send("smtp.qq.com", false))
{
Response.Write("ok");
}
else
{
Response.Write("no");
}
jmail.Close();
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class mailTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string bodystr = "";
bodystr = "一封测试邮件";
jmail.Message jmail = new jmail.Message();
//DateTime t = DateTime.Now;
string subject = "一封测试邮件";
string fromemail = "12345@qq.com";
string toEmail = "ysclc@163.com";
//silent属性:如果设置为true,jmail不会抛出例外错误. jmail. send( () 会根据操作结果返回true或false
jmail.Silent = true;
//jmail创建的日志,前提loging属性设置为true
jmail.Logging = true;
//字符集,缺省为"us-ascii"
jmail.Charset = "gb2312";
//信件的contentype. 缺省是"text/plain") : 字符串如果你以html格式发送邮件, 改为"text/html"即可。
jmail.ContentType = "text/html";
//添加收件人
jmail.AddRecipient(toEmail, "", "");
jmail.From = fromemail;
//发件人邮件用户名
jmail.MailServerUserName = "12345";
//发件人邮件密码
jmail.MailServerPassWord = "password";//qq号密码
//设置邮件标题
jmail.Subject = subject;
//邮件添加附件,(多附件的话,可以再加一条jmail.addattachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的jmail.contenttype="text/html";删掉。否则会在邮件里出现乱码。
//jmail.addattachment( "c:\\test.jpg",true,null);
//邮件内容
jmail.Body = bodystr;
//jmail发送的方法
if (jmail.Send("smtp.qq.com", false))
{
Response.Write("ok");
}
else
{
Response.Write("no");
}
jmail.Close();
}
}
上述代码是案例
具体操作步骤
- 下载jmail.dll(点击下载)
- 本地注册jmail组件(把jmail.dll放入系统盘下system32文件夹下,运行cmd 输入 regsvr32 jmail.dll )
- vs增加对jmail.dll的引用
- 运行上述代码测试即可,上面是最简单都应用,可以根据自己的需求写一自己的类。
个人签名:天行健,君子以自强不息