Click here to Skip to main content
15,885,985 members
Articles / Programming Languages / C#

SMTP and POP3 Mail Server

Rate me:
Please Sign up or sign in to vote.
4.88/5 (96 votes)
29 Sep 20031 min read 1M   18.9K   315  
An SMTP and POP3 mail server written using the .NET Framework and C#.
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace LumiSoft.MailServer
{
	/// <summary>
	/// Summary description for WSqlCommand.
	/// </summary>
	internal class WSqlCommand : IDisposable
	{
		private SqlCommand m_SqlCmd  = null;
		private string     m_connStr = "";
		
		/// <summary>
		/// Default constructor.
		/// </summary>
		/// <param name="connectionString">Connection string.</param>
		/// <param name="commandText">Command text.</param>
		public WSqlCommand(string connectionString,string commandText)
		{
			m_connStr = connectionString;
			
			m_SqlCmd = new SqlCommand(commandText);
			m_SqlCmd.CommandType    = CommandType.StoredProcedure;
			m_SqlCmd.CommandTimeout = 180;
		}

		#region function Dispose

		public void Dispose()
		{
			if(m_SqlCmd != null){
				m_SqlCmd.Dispose();
			}
		}

		#endregion


		#region function AddParameter

		/// <summary>
		/// Adds parameter to Sql Command.
		/// </summary>
		/// <param name="name">Parameter name.</param>
		/// <param name="dbType">Parameter datatype.</param>
		/// <param name="value">Parameter value.</param>
		public void AddParameter(string name,SqlDbType dbType,object value)
		{		
			SqlDbType dbTyp = dbType;
			object val = value;

			if(val is DateTime){
				DateTime date = (DateTime)value;
				val = new DateTime(date.Year,date.Month,date.Day,0,0,0,0);
			}

			if(dbType == SqlDbType.UniqueIdentifier){
				dbTyp = SqlDbType.NVarChar;
				string guid = val.ToString();
				if(guid.Length < 1){
					return;
				}
			}

			m_SqlCmd.Parameters.Add(name,dbTyp).Value = val;
		}

		#endregion

		#region fucntion Execute

		/// <summary>
		/// Executes command.
		/// </summary>
		/// <returns></returns>
		public DataSet Execute()
		{
			DataSet dsRetVal = null;

			using(SqlConnection con = new SqlConnection(m_connStr)){
				con.Open();
				m_SqlCmd.Connection = con;
				
				dsRetVal = new DataSet();
				SqlDataAdapter adapter = new SqlDataAdapter(m_SqlCmd);
				adapter.Fill(dsRetVal);

				adapter.Dispose();
			}

			return dsRetVal;
		}

		#endregion


		#region Properties Implementaion

		/// <summary>
		/// Gets or sets command timeout time.
		/// </summary>
		public int CommandTimeout
		{
			get{ return m_SqlCmd.CommandTimeout; }

			set{ m_SqlCmd.CommandTimeout = value; }
		}

		/// <summary>
		/// Gets or sets command type.
		/// </summary>
		public CommandType CommandType
		{
			get{ return m_SqlCmd.CommandType; }

			set{ m_SqlCmd.CommandType = value; }
		}

		#endregion

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Estonia Estonia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions