Jmail的邮件发送

下载注册dll文件  

1. dll文件下载

2.到jmail.dll所在目录,运行cmd

regsvr32 目录/jmail.dll

3.c#程序中,行首引用代码 using jmail

C#示例代码 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using jmail;
using System.IO;
namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            WebForm1 sendMail = new WebForm1();
         
            //string fj = Server.MapPath("files/JSON.rar");
            string fj = "";
            //sendMail.Send("这是主题", "这是正文", "这是收件人邮箱列表1364386878@qq.com,944132155@qq.com", "这是发件人邮箱地址", "抄送人邮箱列表", "密件人邮箱列表", "附件服务器地址列表");
            sendMail.Send("中胜科技", "", "1364386878@qq.com", "Tonysomnus@163.com", "", "", fj);
            //各列表之间以 英文状态的逗号分分号隔开

        }
        public void Send(string zt, string zw, string getMail, string fromMail, string csMail, string msMail, string fjMail)
        {
            jmail.Message jmessage = new Message(); //Jmail系统配置             
            jmessage.Charset = "GB2312";
            jmessage.Encoding = "base64";  //配置邮件信息            
            jmessage.Subject = zt.Trim();//邮件主题  
            jmessage.HTMLBody = zw;//邮件正文  
            //配置收件人信息  
            string[] sj = getMail.Split(',', ';');
            if (sj.Length > 1)
            {
                for (int i = 0; i < sj.Length; i++)
                {
                    jmessage.AddRecipient(sj[i], "", "");//收件人邮箱地址 
                }
            }
            else
            {
                jmessage.AddRecipient(sj[0], "", "");
            }
            //配置抄送人信息  
            string[] cs = csMail.Split(',', ';');
            if (cs.Length > 1)
            {
                for (int i = 0; i < cs.Length; i++)
                {
                    jmessage.AddRecipientCC(cs[i]);
                }
            }
            else
            {
                jmessage.AddRecipient(cs[0], "", "");
            }
            //配置密送人信息
            string[] ms = msMail.Split(',', ';');
            if (ms.Length > 1)
            {
                for (int i = 0; i < ms.Length; i++)
                {
                    jmessage.AddRecipientBCC(ms[i]);
                }
            }
            else
            {
                jmessage.AddRecipient(ms[0], "", "");
            }
            //配置发件人信息  
            jmessage.ReplyTo = fromMail;//指定收件人回复的,所回复到的地址  
            jmessage.From = fromMail;//邮件发件人的邮箱地址  
            jmessage.FromName = "邮件发件人显示的姓名(李兵泉)!";//邮件发件人显示的姓名  
            jmessage.MailServerUserName = fromMail;//用户名身份验证  
            jmessage.MailServerPassWord = "发送密码填写";//发送邮件在服务器中的密码  
            //配置附件  
            string[] fj = fjMail.Split(',', ';');
            if (fj.Length > 1)
            {
                for (int i = 0; i < fj.Length; i++)
                {
                    jmessage.AddAttachment(fj[i], true, null);
                }
            }
            else
            {
                jmessage.AddRecipient(sj[0], "", "");
            }
            //配置追加信息           
            jmessage.AppendHTML("<table cellspacing='0' cellpadding='0' width='740' align='center' style=\"text-align:left;font-family:'微软雅黑','黑体',arial;\">");
            jmessage.AppendHTML("<tbody><tr><td>");
            jmessage.AppendHTML("<table cellspacing='0' cellpadding='0' width='740' style='text-align:left;color:#75a8f5;font-size:24px;border:5px solid #3e78d1;'>");
            jmessage.AppendHTML("<tbody><tr height='55' style='background-color:#3e78d1;'>");
            jmessage.AppendHTML("<td width='25'>&nbsp;</td>");
            jmessage.AppendHTML("<td width='161' style=\"font-family:'微软雅黑','黑体',arial;\">");
            jmessage.AppendHTML("<img width='136' height='30' style='border:none' title='中胜软件科技' src='http://www.zhongshengruanjian.com/img/logo.png'>");
            jmessage.AppendHTML("</td>");
            jmessage.AppendHTML("<td width='27' style=\"font-family:'微软雅黑','黑体',arial;font-size:24px;\">|</td>");
            jmessage.AppendHTML("<td style=\"font-family:'微软雅黑','黑体',arial;font-size:24px;\">邮箱验证</td>");
            jmessage.AppendHTML("<td></td>");
            jmessage.AppendHTML("</tr></tbody></table>");

            jmessage.AppendHTML("<table cellspacing='0' cellpadding='0' width='740' style='text-align:left;border:5px solid #3e78d1;border-top:none;color:#454545;background-color:#fafafa;font-size:18px;'>");

            jmessage.AppendHTML("<tbody><tr height='25'><td></td></tr>");
            jmessage.AppendHTML("<tr height='45'><td style=\"padding-left:58px;font-size:28px;font-family:'微软雅黑','黑体',arial;font-weight:bold;color:#75a8f5;\"> 您好:</td></tr>");
            jmessage.AppendHTML("<tr height='20'><td></td></tr>");
            jmessage.AppendHTML("<tr height='30'><td style=\"padding-left:58px;padding-right:58px;font-family:'微软雅黑','黑体',arial;font-size:18px;\">");

            jmessage.AppendHTML("感谢您使用XXX邮件服务。</td></tr>");
            jmessage.AppendHTML("<tr height='30'><td style=\"padding-left:58px;padding-right:58px;font-family:'微软雅黑','黑体',arial;font-size:18px;\">");

            jmessage.AppendHTML("请点击以下链接进行邮箱验证,以便开始使用您的XXX帐号:</td></tr>");
            jmessage.AppendHTML("<tr height='80'><td style=\"padding-left:60px;padding-right:60px;font-family:'微软雅黑','黑体',arial;font-size:18px;\">");

            jmessage.AppendHTML("<a style='color: rgb(255,255,255);text-decoration: none;display: block;min-height: 50px;width: 200px;line-height: 50px;background-color:rgb(105,207,78);border-bottom:5px solid #59ae42;font-size:27px;font-weight:bold;text-align:center;' target='_blank' href='https://www.zhongshengruanjian.com'>");
            jmessage.AppendHTML("完成验证</a></td></tr>");
            jmessage.AppendHTML("<tr height='30'><td></td></tr>");
            jmessage.AppendHTML("<tr height='24'><td style=\"padding-left:58px;padding-right:58px;font-family:'微软雅黑','黑体',arial;font-size:14px;color:#8c8c8c;\">如果您无法点击以上链接,请复制以下网址到浏览器里直接打开:</td></tr>");
            jmessage.AppendHTML("<tr height='48'>");

            jmessage.AppendHTML("<td style=\"padding-left:58px;padding-right:65px;font-family:'微软雅黑','黑体',arial;line-height:24px;\">");
            jmessage.AppendHTML("<a target='_blank' href='https://www.zhongshengruanjian.com' style='color:#3e78d1;font-size:14px;'>");
            jmessage.AppendHTML("https://www.zhongshengruanjian.com");

            jmessage.AppendHTML("</a></td></tr>");
            jmessage.AppendHTML("<tr height='24'><td style=\"padding-left:58px;padding-right:58px;font-family:'微软雅黑','黑体',arial;font-size:13px;color:#919191;line-height:24px;\">    ");
            jmessage.AppendHTML("如果您并未申请XXX帐号,可能是其他用户误输入了您的邮箱地址。请忽略此邮件,或与我们联系。</td></tr>");
            jmessage.AppendHTML("<tr height='50'><td></td></tr></tbody>");
            jmessage.AppendHTML("</table>");
            jmessage.AppendHTML("<table cellspacing=\"0\" cellpadding=\"0\" width=\"740\" style=\"color:#969696;font-size:12px;vertical-align:middle;text-align:center;\">");
            jmessage.AppendHTML("<tbody>");
            jmessage.AppendHTML("<tr height=\"5\"><td></td></tr>");
            jmessage.AppendHTML("<tr height=\"20\">");
            jmessage.AppendHTML("<td width=\"1\" style=\"text-align:left;font-family:'微软雅黑','黑体',arial\">");      
            jmessage.AppendHTML("<a title=\"\" style=\"text-decoration:none;color:#969696;padding-left:5px;\" target=\"_blank\" href=\"\"></a>");
            jmessage.AppendHTML("</td><td>24小时全国服务热线:400-0000-000</td>");
            jmessage.AppendHTML("<td width=\"436\">服务邮箱:");
            jmessage.AppendHTML("<a title=\"邮件\" style=\"text-decoration:none;color:#969696;padding-left:10px;\" target=\"_blank\" href=\"mailto:zhongshengruanjian@qq.com\">zhongshengruanjian@qq.com</a>");
            jmessage.AppendHTML("</td></tr><tr height=\"20\">");
            jmessage.AppendHTML("<td colspan=\"2\" style=\"text-align:left;font-family:'微软雅黑','黑体',arial\">");
            jmessage.AppendHTML("<a title=\"公司官网\" style=\"text-decoration:none;color:#92b1e0;padding-right:3px;\" target=\"_blank\" href=\"http://www.zhongshengruanjian.com/\">中胜科技官网</a>");
            jmessage.AppendHTML("/");
            jmessage.AppendHTML("<a title=\"公司官网\" style=\"text-decoration:none;color:#92b1e0;padding-left:3px;padding-right:3px;\" target=\"_blank\"  href=\"http://www.zhongshengruanjian.com/\">中胜科技官网</a>");
            jmessage.AppendHTML("</td></tr><tr height='45'><td></td></tr>");
            jmessage.AppendHTML("</tbody></table></td></tr></tbody></table>");
           // Response.Write(jmessage.Text);
            //发送邮件  
            for (int i = 0; i < sj.Length; i++)
            {
                jmessage.Send("smtp.163.com", false);//发送邮件服务器  
            }
            //配置jmail日志
            jmessage.Logging = true;
            using (StreamWriter sw = new StreamWriter("E:\\log.txt", true))
            {
                sw.Write(jmessage.Log);
                sw.Close();
            }
            jmessage.Close();//邮件发送完毕,关闭邮件发送状态  
        }
    }
}
View Code

 

效果图 

转载于:https://www.cnblogs.com/DemoLee/p/3991172.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值