用Jmail实现邮件发送源代码

以下代码经过测试,没有问题的,可以实现邮件发送。
JMail下载地址:http://www.newhua.com/soft/1027.htm
记得在使用Jmail的时候要添加引用。

None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Configuration;
None.gif
using  System.Web;
None.gif
using  System.Web.Security;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.WebControls.WebParts;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Web.Mail;
None.gif
using  System.Web.Util;
None.gif
using  jmail;
None.gif
None.gif
public  partial  class  _Default : System.Web.UI.Page 
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif    
protected void Button1_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        jmail.Message Jmail 
= new jmail.MessageClass();
InBlock.gif        DateTime t 
= DateTime.Now;
InBlock.gif        String Subject 
= this.txtSubject.Text;
InBlock.gif        String Body 
= this.txtBody.Text;
InBlock.gif        String FromEmail 
= this.txtFromEmail.Text;
InBlock.gif        String ToEmail 
= this.txtToEmail.Text;
InBlock.gif        
//Silent属性:如果设置为true,JMail不会抛出例外错误.
InBlock.gif
        Jmail.Silent = true;
InBlock.gif        
//Jmail创建的日志,前提loging属性设置为true
InBlock.gif
        Jmail.Logging = true;
InBlock.gif        
//字符集,缺省为"US-ASCII"
InBlock.gif
        Jmail.Charset = "GB2312";
InBlock.gif        
//信件的contentype. 缺省是"text/plain" 字符串如果你以HTML格式发送邮件, 改为"text/html"即可。
InBlock.gif
        Jmail.ContentType = "text/html";
InBlock.gif        
//添加收件人
InBlock.gif
        Jmail.AddRecipient(ToEmail, """");
InBlock.gif        
//发件人邮件用户名
InBlock.gif
        Jmail.From = FromEmail;
InBlock.gif        
//发件人邮件用户名
InBlock.gif
        Jmail.MailServerUserName = this.txtUserName.Text;
InBlock.gif        
//发件人邮件密码
InBlock.gif
        Jmail.MailServerPassWord = this.txtPassword.Text;
InBlock.gif        
//设置邮件标题
InBlock.gif
        Jmail.Subject = Subject;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**/////邮件添加附件(增加附件可再加一条Jmail.AddAttachment( "c:\\test.jpg",true,null);就可以搞定了。
ExpandedSubBlockEnd.gif        
////增加附件后要把上面的Jmail.ContentType="text/html";删掉,否则会在邮件里出现乱码。

InBlock.gif        //Jmail.AddAttachment("c:\\test.jpg", true, null);
InBlock.gif
InBlock.gif        
//邮件内容
InBlock.gif
        Jmail.Body = Body+t.ToString();
InBlock.gif        
//设置SMTP服务器
InBlock.gif
        Jmail.Send("smtp.126.com"false);
InBlock.gif        
//关闭Jmail连接
InBlock.gif
        Jmail.Close();
InBlock.gif
InBlock.gif        Response.Write(
"发送成功");
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}

None.gif
None.gif

转载于:https://www.cnblogs.com/zhangyi85/archive/2007/06/12/780189.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值