Click here to Skip to main content
15,895,142 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.IO;
using System.Data;

namespace LumiSoft.MailServer
{
	/// <summary>
	/// Provides methods to handle messages(store,retrieve,...).
	/// </summary>
	public class MailStore
	{
		private static string m_MailStorePath = "";


		#region function GetMessageList

	/*	/// <summary>
		/// Get user mail messages.
		/// </summary>
		/// <param name="mailbox"></param>
		/// <param name="e"></param>
		public static void GetMessageList(string mailbox,LumiSoft.Net.POP3.Server.GetMessagesInfo_EventArgs e)
		{
			try
			{	
				MailServer.API.GetMessageList(mailbox,e.Messages);
			}
			catch(Exception x)
			{				
				Error.DumpError(x,new System.Diagnostics.StackTrace());
			}
		}
*/
		#endregion


		#region function StoreMessage
/*
		/// <summary>
		/// Stores message to specifeied mailbox.
		/// </summary>
		/// <param name="mailbox">Mailbx name.</param>
		/// <param name="msgStream">Message stream.</param>
		/// <param name="to">Receptient e-adress.</param>
		/// <param name="from">Sender e-address.</param>
		/// <param name="relay">Specifies if message must be stored to relay folder.</param>
		public static void StoreMessage(string mailbox,MemoryStream msgStream,string to,string from,bool relay)
		{
			try
			{	
			//	if(relay){ // Code movet to server api
			//		// Create dummy file name
			//		string filename = Guid.NewGuid().ToString();
			//		       filename = filename.Substring(0,22);
			//	           filename = filename.Replace("-","_");
//
//					string path = m_MailStorePath + "Relay\\";
//
//					// Check if Directory exists, if not Create
//					if(!Directory.Exists(path)){
//						Directory.CreateDirectory(path);
//					}
//
//					//---- Write message data to file -------------------------------//
//					using(FileStream fStream = File.Create(path + "\\" + filename + ".eml",(int)msgStream.Length)){
//
//						// Write internal relay info line at the beginning of messsage.
//						// Note: This line is skipped when sending to destination host,
//						// actual message begins from 2 line.
//						// Header struct: 'RelayInfo:IsUndeliveredWarningSent<TAB>To<TAB>Sender<TAB>Date\r\n'
//						string internalServerHead = "RelayInfo:0\t" + to + "\t" + from + "\t" + DateTime.Now.ToString("r",System.Globalization.DateTimeFormatInfo.InvariantInfo) + "\r\n";
//						byte[] sHead = System.Text.Encoding.Default.GetBytes(internalServerHead);
//						fStream.Write(sHead,0,sHead.Length);
//
//						msgStream.WriteTo(fStream);
//					}
//					//---------------------------------------------------------------//
//				}
//				else{
					MailServer.API.StoreMessage(mailbox,msgStream,to,from,relay);
			//	}
				
			}
			catch(Exception x)
			{
				Error.DumpError(x,new System.Diagnostics.StackTrace());
			}
		}
*/
		#endregion

		#region function GetMessage

/*		/// <summary>
		/// Gets Mail Message from specified Mailbox.
		/// </summary>
		/// <param name="mailbox">Mailbox name</param>
		/// <param name="msgID">Message MessageID</param>
		/// <returns></returns>
		public static byte[] GetMessage(string mailbox,string msgID)
		{
			byte[] retVal = null;

			try
			{
				retVal = MailServer.API.GetMessage(mailbox,msgID);
			}
			catch(Exception x)
			{
				Error.DumpError(x,new System.Diagnostics.StackTrace());
			}

			return retVal;
		}*/

		#endregion

		#region function DeleteMessage

	/*	/// <summary>
		/// Deletes Message from specified Mailbox.
		/// </summary>
		/// <param name="mailbox">Mailbox name</param>
		/// <param name="msgID">MessageID.</param>
		public static void DeleteMessage(string mailbox,string msgID)
		{
			try
			{
				MailServer.API.DeleteMessage(mailbox,msgID);
			}
			catch(Exception x)
			{
				Error.DumpError(x,new System.Diagnostics.StackTrace());
			}
		}*/

		#endregion


		#region Properties Implementation

		/// <summary>
		/// Gets or set mail store path.
		/// </summary>
		public static string MailStorePath
		{
			get{ return m_MailStorePath; }

			set{ m_MailStorePath = 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