zoukankan      html  css  js  c++  java
  • 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. 运行上述代码测试即可,上面是最简单都应用,可以根据自己的需求写一自己的类。
  • 相关阅读:
    C# checklistbox控件用法总结(怎样得到多选的值,以及动态加载数据)
    Tomcat service.xml详解
    修改windows服务器上面tomcat启动窗口的名称
    表空间
    安装selenium遇到的问题
    oracel 锁表查询
    Can not perform this action after onSaveInstanceState
    Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.HEADSET_PLUG
    Java.lang.IllegalStateException Activity has been destroyed
    StrictMode 使用
  • 原文地址:https://www.cnblogs.com/clc2008/p/1954816.html
Copyright © 2011-2022 走看看