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