严重申明:本方案中的两个工程由Dimac.JMail逆向生成,版权归Dimac公司所。任何单位或个人不得将工程里的任何代码用于商业用途。本工程只做讨论及学习使用。对于其它行为的,对当事人自己负全部的责任。对于下载本测试代码的任何人,都视为同意此申明里的所有内容。
不知道MS对此会有怎样的说明。对于一个生成DLL的文件,可以用工具轻松的逆向转化为工程文件,而且可以通过编译而后编译成与源DLL字节大小完全一样的文件来,而且可以正常使用。
对于一些大一点的DLL文件,可能逆向出来的文件很多,所以编译一时不能通过,但经过细心的修改后,也还是可以的。测试过三个项目,一个是MS自己的Web Controls,第二个是MS的WebService文件,而另一个是Dimac的JMail。前面两个有些复杂,短时间内无法修改让其通过编译,而对于Dimac.JMail,经过小的改动,可以通过编译,且正常工作。
索性加上自己以前写的Mail管理类,然后一起做一个小测试项目。
部份代码:
IMail接口:
using System;
![](/Images/OutliningIndicators/None.gif)
namespace Webb.WAVE.Controls
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// Summary description for Webb.
/// </summary>
public interface IEMail:IDisposable
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string ServerName
{get;set;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string ServerLoginName
{get;set;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string ServerLoginPassword
{set;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string Subject
{set;get;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string Body
{set;get;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string HTMLBody
{set;get;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string From
{set;get;}
//
void AddToAddress(string i_address);
void AddCcAddress(string i_address);
void SendEMail();
}
}
JMailDotNet类:
using System;
using Dimac.JMail;
using System.Data;
![](/Images/OutliningIndicators/None.gif)
namespace Webb.WAVE.Controls
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///
/// </summary>
public class JMailDotNet:IEMail
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Fields#region Fields
private string m_server;
private string m_loginName;
private string m_password;
private string m_from;
private Message m_message;
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Properties#region Properties
// public Message MailMessage
// {
// get{return this.m_message;}
// set{this.m_message = value;}
// }
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
public JMailDotNet()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_message = new Message();
}
![](/Images/OutliningIndicators/InBlock.gif)
public JMailDotNet(bool i_systemServer)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_message = new Message();
// this.m_password = WaveSystem.SystemVarible["EmailServerPassword"].ToString();
// this.m_loginName = WaveSystem.SystemVarible["EmailServerLoginName"].ToString();
// this.m_server = WaveSystem.SystemVarible["EmailServer"].ToString();
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
IEMail Members#region IEMail Members
public string ServerName
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{return this.m_server;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{this.m_server = value;}
}
public string ServerLoginName
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{return this.m_loginName;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{this.m_loginName = value;}
}
public string ServerLoginPassword
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{this.m_password = value;}
}
public string Subject
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{return this.m_message.Subject;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{this.m_message.Subject = value;}
}
public string Body
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{return this.m_message.BodyText;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{this.m_message.BodyText = value;}
}
public string HTMLBody
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{return this.m_message.BodyHtml;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{this.m_message.BodyHtml = value;}
}
public string From
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{return this.m_from;}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{this.m_from = value;}
}
public void AddToAddress(string i_address)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.m_message.To.Add(new Address(i_address));
}
public void AddCcAddress(string i_address)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.m_message.Cc.Add(new Address(i_address));
}
public void SendEMail()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Smtp m_SMTPServer = new Smtp();
m_SMTPServer.Domain = this.m_server;
m_SMTPServer.Password = this.m_password;
m_SMTPServer.UserName = this.m_loginName;
m_SMTPServer.HostName = this.m_server;
this.m_message.From = new Address(this.m_from);
m_SMTPServer.Authentication =SmtpAuthentication.Login;
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_SMTPServer.Send(this.m_message);
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//*
catch(SmtpAuthNotSupportedException ex)
{
//WaveTrace.TraceMsg(ex.Message);
//throw new Exception("EMail sent error, all message send faild.");
}
catch(LoginFailedException ex)
{
//WaveTrace.TraceMsg(ex.Message);
//throw new Exception("EMail sent error, all message send faild.");
}
catch(SmtpException ex)
{
//WaveTrace.TraceMsg(ex.Message);
//throw new Exception("EMail sent error, all message send faild.");
}
catch(ConnectionException ex)
{
//WaveTrace.TraceMsg(ex.Message);
//throw new Exception("EMail sent error, all message send faild.");
}
catch(ArgumentNullException ex)
{
//WaveTrace.TraceMsg(ex.Message);
//throw new Exception("EMail sent error, all message send faild.");
}
*/
catch(JMailException)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// WaveHelper.TraceMsg(ex.Message);
throw new Exception("EMail sent error, all message send faild.");
}
finally
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_SMTPServer = null;
}
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
IDisposable Members#region IDisposable Members
![](/Images/OutliningIndicators/InBlock.gif)
public void Dispose()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.m_message = null;
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
}
}
![](/Images/OutliningIndicators/None.gif)
邮件管理类:其中注释掉了在其它项目里使用的函数,但这些函数也可以做为学习的例子。
using System;
using System.Data;
using Dimac.JMail;
![](/Images/OutliningIndicators/None.gif)
namespace Webb.WAVE.Controls
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// Summary description for Webb.
/// </summary>
public enum MailType
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
JMailCom = 0,
JMailDotNet = 1,
EMailMessage = 2,
Default = 3
}
![](/Images/OutliningIndicators/InBlock.gif)
public class WaveEMailManager:IDisposable
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Fields#region Fields
private IEMail m_email;
private MailType m_mailType;
// private WaveEMail m_dbmail;
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Properties#region Properties
public IEMail EMail
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{return this.m_email;}
}
public MailType EMailType
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{return this.m_mailType;}
}
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///
/// </summary>
public WaveEMailManager()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///
/// </summary>
/// <param name="i_MailType"></param>
public WaveEMailManager(MailType i_MailType)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.m_mailType = i_MailType;
if(i_MailType==MailType.JMailCom)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.m_email = new JMailCOM(true) as IEMail;
}
else if(i_MailType==MailType.JMailDotNet)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.m_email = new JMailDotNet(true) as IEMail;
}
else if(i_MailType==MailType.EMailMessage)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.m_email = new EMailMessage(true) as IEMail;
}
else if(i_MailType==MailType.Default)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string m_control = "msg";//WaveSystem.SystemVarible["EmailControl"].ToString();
switch(m_control)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
case "com":
this.m_email = new JMailCOM(true) as IEMail;
this.m_mailType = MailType.JMailCom;
break;
case "net":
this.m_email = new JMailDotNet(true) as IEMail;
this.m_mailType = MailType.JMailDotNet;
break;
case "msg":
this.m_email = new EMailMessage(true) as IEMail;
this.m_mailType = MailType.EMailMessage;
break;
default:
this.m_email = new EMailMessage(true) as IEMail;
this.m_mailType = MailType.EMailMessage;
break;
}
}
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///
/// </summary>
/// <param name="i_mailID"></param>
public void SendDbEmailByID(long i_mailID)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// if(this.m_dbmail==null){this.m_dbmail = new WaveEMail();}
// m_dbmail.LoadData(i_mailID);
// this.m_email.HTMLBody = this.m_dbmail.HTMLBody;
// this.m_email.AddToAddress(this.m_dbmail.To);
// this.m_email.Subject = this.m_dbmail.Subject;
// try{this.m_email.SendEMail();}
// catch(Exception ex){WaveHelper.TraceMsg(ex.Message);throw ex;}
// m_dbmail.SentTimes++;
// m_dbmail.UpdateData();
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Static functions#region Static functions
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///
/// </summary>
/// <param name="i_mailID"></param>
static public void DeleteEMail(long i_mailID)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// this.m_dbManager = new OleDBManager(true) as IOleDBManager;
// this.m_dbManager.Command = new System.Data.OleDb.OleDbCommand();
// ISqlDBManager m_dbManager = new SqlDBManager(true) as ISqlDBManager;
// m_dbManager.Command = new System.Data.SqlClient.SqlCommand();
// m_dbManager.Command.CommandText = SQLCommandText.T_Emails.T_Emails_DeleteByID;
// m_dbManager.Command.Parameters.Add("@log_id",i_mailID);
// try{m_dbManager.ExecuteNonQuery();}
// catch(Exception ex){WaveHelper.TraceMsg(ex.Message);throw ex;}
// m_dbManager.Dispose();
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///
/// </summary>
/// <param name="i_table"></param>
static public void GetAllEmails(DataTable i_table)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// this.m_dbManager = new OleDBManager(true) as IOleDBManager;
// this.m_dbManager.Command = new System.Data.OleDb.OleDbCommand();
// ISqlDBManager m_dbManager = new SqlDBManager(true) as ISqlDBManager;
// m_dbManager.Command = new System.Data.SqlClient.SqlCommand();
// m_dbManager.Command.CommandText = SQLCommandText.T_Emails.T_Emails_SelectAllMails;
// try{m_dbManager.FillDataTable(i_table);}
// catch(Exception ex){WaveHelper.TraceMsg(ex.Message);throw ex;}
// m_dbManager.Dispose();
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
///
/// </summary>
/// <param name="i_send"></param>
static public void DeleteAllSendMail(int i_send)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// this.m_dbManager = new OleDBManager(true) as IOleDBManager;
// this.m_dbManager.Command = new System.Data.OleDb.OleDbCommand();
// ISqlDBManager m_dbManager = new SqlDBManager(true) as ISqlDBManager;
// m_dbManager.Command = new System.Data.SqlClient.SqlCommand();
// m_dbManager.Command.CommandText = SQLCommandText.T_Emails.T_Emails_DeleteBySent;
// m_dbManager.Command.Parameters.Add("@int_sent",i_send);
// try{m_dbManager.ExecuteNonQuery();}
// catch(Exception ex){WaveHelper.TraceMsg(ex.Message);throw ex;}
// m_dbManager.Dispose();
}
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
IDisposable Members#region IDisposable Members
public void Dispose()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(this.m_email!=null)this.m_email.Dispose();
}
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
}
}
![](/Images/OutliningIndicators/None.gif)
请不要修改邮箱的密码,如果须要,请自行申请邮箱帐号。另外,JMailCOM须要安装JMail的COM组件,工程里引用了这个文件,但对于没有安装该组件的不能正常使用这个类型的邮件服务。
![Dimac.JMail.TestForm.JPG](/images/cnblogs_com/wucountry/2006_02/Dimac.JMail.TestForm.JPG)
项目源代码下载:[请认阅读申明]
严重申明:本方案中的两个工程由Dimac.JMail逆向生成,版权归Dimac公司所。任何单位或个人不得将工程里的任何代码用于商业用途。本工程只做讨论及学习使用。对于其它行为的,对当事人自己负全部的责任。对于下载本测试代码的任何人,都视为同意此申明里的所有内容。
https://files.cnblogs.com/WuCountry/Webb.JMail.zip
不好意思,刚才搞错了文件,对于已经下载的朋友表示报谦。。。。