asp.net中应用Jmail

1.在命令提示符中注册JMail:regsvr32 c:\jmail.dll(注:jmail.dll放在C盘根目录)
2.卸载Jmail:regsvr32 /u jmail.dll
3.在BIN文件夹增加引用Jmail.dll

 

#region//Jmail发邮件
    /// <summary>
    ///
    /// </summary>
    /// <param name="sendName">发送帐号用户名</param>
    /// <param name="sendPass">发送帐号密码</param>
    /// <param name="fromMail">发件人邮箱</param>
    /// <param name="serverMail">发送帐号服务器</param>
    /// <param name="receiveMail">接收帐号</param>
    /// <param name="mailSubject">邮件主题</param>
    /// <param name="mailBody">邮件内容</param>
    public void JMailSend(string sendName,string sendPass,string fromMail,string serverMail,string receiveMail,string mailSubject,string mailBody)
    {
        jmail.Message jmail = new jmail.Message();
        //Silent属性:如果设置为true,JMail不会抛出例外错误. 
        jmail.Silent = true;
        //Jmail创建的日志,前提loging属性设置为true 
        jmail.Logging = true;
        //字符集,缺省为"US-ASCII" 
        jmail.Charset = "GB2312";
        //设置邮件的编码方式 
        jmail.Encoding = "Base64";
        //信件contentype. 缺省是text/plain;如果你以HTML格式发送邮件, 改为"text/html"即可。 
        //jmail.ContentType = "text/html"; 
        //添加收件人 可以增加多个收件人
        jmail.AddRecipient(receiveMail, "", "");
        //添加抄送人  可以增加多个抄送人
        //jmail.AddRecipientCC("[email protected]", "", "");
        //发件人邮箱 
        jmail.From = fromMail;
        //发件人邮件用户名 
        jmail.MailServerUserName = sendName;
        //发件人邮件密码 
        jmail.MailServerPassWord = sendPass;
        //设置邮件标题 
        jmail.Subject = mailSubject;
        //邮件添加附件,(注:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。) 
        string path = "E:\\Jmail.rar";
        jmail.AddAttachment(path, true, null);
        //邮件内容,当你发送附件而邮件内容又包含html标签时这个是最好的解决方案了 
        jmail.HTMLBody = mailBody;
        //Jmail发送的方法
        try
        {
            jmail.Send(serverMail, false);
        }
        catch (Exception ex) { throw ex; }
        finally { jmail.Close(); }

    }
    #endregion

    protected void Button2_Click(object sender, EventArgs e)
    {
        string sendName = "good";
        string sendPass = "goodteam";
        string fromMail = "[email protected]";
        string serverMail = "mail.163.com";
        string receiveMail = "[email protected]";
        string mailSubject = "你大爷我今天测试了";
        string mailBody = "测试通过!";
        JMailSend(sendName, sendPass, fromMail, serverMail,receiveMail, mailSubject, mailBody);
    }

你可能感兴趣的:(职场,asp.net,jmail,休闲)