• 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();



        }
    }

    上述代码是案例

    具体操作步骤

    1. 下载jmail.dll(点击下载)
    2. 本地注册jmail组件(把jmail.dll放入系统盘下system32文件夹下,运行cmd 输入  regsvr32   jmail.dll )
    3. vs增加对jmail.dll的引用
    4. 运行上述代码测试即可,上面是最简单都应用,可以根据自己的需求写一自己的类。
  • 相关阅读:
    个人觉得在前台比较通用的校验的提示方法
    平时面试总结
    sturts2批量导入excel中的信息入库大致代码
    在B/S系统中得到spring的ApplicationContext对象的一点小技巧
    Oracle同义词创建及其作用
    Oracle中创建dblink的方法
    真实项目中struts2 导出excel文件
    十二款jQuery插件(编辑器,图片,验证等)
    华丽到暴表的网站 cnn ecosphere
    Mysql 临时表
  • 原文地址:https://www.cnblogs.com/clc2008/p/1954816.html
Copyright © 2020-2023  润新知