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 = "goodteam@163..com";
        string serverMail = "mail.163.com";
        string receiveMail = "[email protected]";
        string mailSubject = "你大爺我今天測試了";
        string mailBody = "測試通過!";
        JMailSend(sendName, sendPass, fromMail, serverMail,receiveMail, mailSubject, mailBody);
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章