Click here to Skip to main content
15,895,538 members
Articles / Programming Languages / C#
Article

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   313
An SMTP and POP3 mail server written using the .NET Framework and C#.

Sample Image - smtppop3mailserver.jpg

Introduction

The MailServerComponent implements POP3 and SMTP (core) servers. It Handles lowlevel POP3 and SMTP commands and raises events according to it. The MailServer service just handles MailServerComponent events and does mail retrieving and storing job.

Features

General:

  • SMTP/POP3/IMAP4/WebMail
  • IP access filtering
  • User mailbox size limit
  • Supports XML or MSSQL databases
  • Nice GUI for administation
  • Well commented source code included

SMTP:

  • All basic SMTP features  
  • Supports multiple domains  
  • Supports multiple e-address for one mailbox  
  • Supports aliases(Mailing lists). Supports public and private(needs authentication) lists.
  • Supports email routing. eg *ivar* pattern routes all addresses containing ivar to specified mailbox or remote address  
  • SMTP AUTH (LOGIN CRAM-MD5) (supported authentication types)  
  • SMTP SIZE, PIPELINING, 8BITMIME, CHUNCKING support  
  • SMTP custom message filters  
  • Relay can be controlled by IP access or authentication

POP3:

  • All basic POP3 features
  • APOP command for secure authentication
  • POP3 AUTH (LOGIN CRAM-MD5) (supported authentication types)
  • POP3 remote accounts

WebMail (ASP.NET):

  • Standalone webmail, can be used any with IMAP based mailserver
  • Supports XML or MSSQL databases
  • Multiple UI languages (ENG,EST,RUS)

Notes

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

 
GeneralRe: Bouncing Pin
Anonymous16-Aug-04 19:38
Anonymous16-Aug-04 19:38 
GeneralRe: Bouncing Pin
JDBP17-Aug-04 4:51
JDBP17-Aug-04 4:51 
GeneralRe: Bouncing Pin
Anonymous17-Aug-04 7:12
Anonymous17-Aug-04 7:12 
GeneralRe: Bouncing Pin
JDBP17-Aug-04 7:24
JDBP17-Aug-04 7:24 
GeneralRouting to multiple recipients Pin
eplanet10-Aug-04 18:39
eplanet10-Aug-04 18:39 
GeneralRe: Routing to multiple recipients Pin
Anonymous15-Aug-04 0:40
Anonymous15-Aug-04 0:40 
GeneralRe: Routing to multiple recipients Pin
eplanet15-Aug-04 4:03
eplanet15-Aug-04 4:03 
Generaltrying to implement webmail Pin
heliosphan8-Aug-04 12:16
heliosphan8-Aug-04 12:16 
Hi, I'm trying to run the webmail component. If I run it preserving the directory structure from the original file (placing the first MailServer directory under c:\inetpub\wwwroot so IIS can see it) I get the following error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'LumiSoft' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 5: <%@ Import Namespace="System.Data.SqlClient" %>
Line 6:
Line 7: <%@ Import Namespace="LumiSoft.Net.IMAP.Client" %>
Line 8: <%@ Import Namespace="LumiSoft.Wisk.Text" %>
Line 9: <%@ Import Namespace="Npgsql"%>


Source File: C:\Inetpub\wwwroot\MailServer\webmail\login.aspx Line: 7






If I just use the webmail directory and put that under inetpub\wwwroot I get the login page, but when I try to log in it says: No connection could be made because the target machine actively refused it.

I set up al of the SQL Server tables and stored procedures. I set up a login both in the users table and also within the mail manager. I set up the mail server and it is running fine. Any ideas on this?

Regards,

Dinesh

P.S. This is a great example keep up the good work

irective or an assembly reference?)
C:\Inetpub\wwwroot\MailServer\webmail\login.aspx(8,11): error CS0246: The type or namespace name 'LumiSoft' could not be found (are you missing a using directive or an assembly reference?)
C:\Inetpub\wwwroot\MailServer\webmail\login.aspx(9,11): error CS0246: The type or namespace name 'Npgsql' could not be found (are you missing a using directive or an assembly reference?)
C:\Inetpub\wwwroot\MailServer\webmail\login.aspx(15,9): error CS0246: The type or namespace name 'WText' could not be found (are you missing a using directive or an assembly reference?)


Show Complete Compilation Source:

Line 1: //------------------------------------------------------------------------------
Line 2: // <autogenerated>
Line 3: // This code was generated by a tool.
Line 4: // Runtime Version: 1.1.4322.573
Line 5: //
Line 6: // Changes to this file may cause incorrect behavior and will be lost if
Line 7: // the code is regenerated.
Line 8: //
Line 9: //------------------------------------------------------------------------------
Line 10:
Line 11: namespace ASP {
Line 12: using System;
Line 13: using System.Collections;
Line 14: using System.Collections.Specialized;
Line 15: using System.Configuration;
Line 16: using System.Text;
Line 17: using System.Text.RegularExpressions;
Line 18: using System.Web;
Line 19: using System.Web.Caching;
Line 20: using System.Web.SessionState;
Line 21: using System.Web.Security;
Line 22: using System.Web.UI;
Line 23: using System.Web.UI.WebControls;
Line 24: using System.Web.UI.HtmlControls;
Line 25:
Line 26: #line 3 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 27: using System.IO;
Line 28:
Line 29: #line default
Line 30: #line hidden
Line 31:
Line 32: #line 4 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 33: using System.Data;
Line 34:
Line 35: #line default
Line 36: #line hidden
Line 37:
Line 38: #line 5 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 39: using System.Data.SqlClient;
Line 40:
Line 41: #line default
Line 42: #line hidden
Line 43:
Line 44: #line 7 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 45: using LumiSoft.Net.IMAP.Client;
Line 46:
Line 47: #line default
Line 48: #line hidden
Line 49:
Line 50: #line 8 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 51: using LumiSoft.Wisk.Text;
Line 52:
Line 53: #line default
Line 54: #line hidden
Line 55:
Line 56: #line 9 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 57: using Npgsql;
Line 58:
Line 59: #line default
Line 60: #line hidden
Line 61:
Line 62:
Line 63: public class login_aspx : System.Web.UI.Page, System.Web.SessionState.IRequiresSessionState {
Line 64:
Line 65: private static bool __initialized = false;
Line 66:
Line 67: private static object __stringResource;
Line 68:
Line 69: private static System.Collections.ArrayList __fileDependencies;
Line 70:
Line 71:
Line 72: #line 11 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 73:
Line 74:
Line 75: private bool m_errors = false;
Line 76: private string m_ErrorText = "";
Line 77: private WText m_WTxt = null;
Line 78:
Line 79: protected override void OnLoad(EventArgs e)
Line 80: {
Line 81: base.OnLoad(e);
Line 82:
Line 83: m_WTxt = new WText(Request.PhysicalApplicationPath + "bin\\",Application["DefaultLanguage"].ToString());
Line 84:
Line 85: if(Request.Params["Name"] != null && Request.Params["Password"] != null){
Line 86:
Line 87: IMAP_Client clnt = new IMAP_Client();
Line 88: bool isConnected = false;
Line 89:
Line 90: try{
Line 91: clnt.Connect(Application["IMAPServerName"].ToString(),Convert.ToInt32(Application["IMAPServerPort"]));
Line 92: isConnected = true;
Line 93: clnt.Authenticate(Request.Params["Name"],Request.Params["Password"]);
Line 94:
Line 95: Session.Add("Name", Request.Params["Name"]);
Line 96: Session.Add("Password", Request.Params["Password"]);
Line 97:
Line 98: switch(Application["DatabaseType"].ToString().ToLower())
Line 99: {
Line 100: case "mssql":
Line 101: using(SqlConnection conn = new SqlConnection(Application["connStr"].ToString())){
Line 102: conn.Open();
Line 103:
Line 104: DataSet ds = new DataSet();
Line 105: using(SqlCommand cmd = new SqlCommand("GetUserID",conn)){
Line 106: cmd.CommandType = CommandType.StoredProcedure;
Line 107: cmd.Parameters.Add( "@LoginName" ,SqlDbType.NVarChar).Value = Request.Params["Name"];
Line 108:
Line 109: using(SqlDataAdapter sqlCmd = new SqlDataAdapter(cmd)){
Line 110: sqlCmd.Fill(ds);
Line 111: }
Line 112: }
Line 113:
Line 114: if(ds.Tables[0].Rows.Count > 0){
Line 115: Session.Add("userEmail", ds.Tables[0].Rows[0]["Email"].ToString());
Line 116: Session.Add("deleteFolder", ds.Tables[0].Rows[0]["DeleteFolder"].ToString());
Line 117: Session.Add("sentFolder", ds.Tables[0].Rows[0]["SentFolder"].ToString());
Line 118: }
Line 119: }
Line 120:
Line 121: break;
Line 122:
Line 123: case "pgsql":
Line 124: using(NpgsqlConnection con = new NpgsqlConnection(Application["connStr"].ToString())){
Line 125: con.Open();
Line 126:
Line 127: DataSet ds = new DataSet();
Line 128: string cmdText = "select * from lspr_login('" + Request.Params["Name"] + "')";
Line 129: using(NpgsqlCommand cmd = new NpgsqlCommand(cmdText,con)){
Line 130:
Line 131: using(NpgsqlDataAdapter sqlCmd = new NpgsqlDataAdapter(cmd)){
Line 132: sqlCmd.Fill(ds);
Line 133: }
Line 134: }
Line 135:
Line 136: if(ds.Tables[0].Rows.Count > 0){
Line 137: Session.Add("userEmail", ds.Tables[0].Rows[0]["Email"].ToString());
Line 138: Session.Add("deleteFolder", ds.Tables[0].Rows[0]["DeleteFolder"].ToString());
Line 139: Session.Add("sentFolder", ds.Tables[0].Rows[0]["SentFolder"].ToString());
Line 140: }
Line 141: }
Line 142: break;
Line 143:
Line 144: case "xml":
Line 145: if(!File.Exists(Request.PhysicalApplicationPath + "data\\" + Request.Params["Name"] + ".xml")){
Line 146: DataSet ds = new DataSet();
Line 147:
Line 148: ds.Tables.Add("Settings");
Line 149: ds.Tables["Settings"].Columns.Add("Email");
Line 150: ds.Tables["Settings"].Columns.Add("DeleteFolder");
Line 151: ds.Tables["Settings"].Columns.Add("SentFolder");
Line 152: ds.Tables["Settings"].Rows.Add(new object[]{"","",""});
Line 153:
Line 154: ds.Tables.Add("Contacts");
Line 155: ds.Tables["Contacts"].Columns.Add("ForName");
Line 156: ds.Tables["Contacts"].Columns.Add("SurName");
Line 157: ds.Tables["Contacts"].Columns.Add("Email");
Line 158: ds.Tables["Contacts"].Columns.Add("Phone1");
Line 159: ds.Tables["Contacts"].Columns.Add("Phone2");
Line 160: ds.Tables["Contacts"].Columns.Add("ContactID");
Line 161:
Line 162: try{
Line 163: ds.WriteXml(Request.PhysicalApplicationPath + "data\\" + Request.Params["Name"] + ".xml",XmlWriteMode.WriteSchema);
Line 164: }
Line 165: catch{
Line 166: m_ErrorText = "Folder " + Request.PhysicalApplicationPath + "data\\" + " has no write permission!";
Line 167: }
Line 168: }
Line 169:
Line 170: DataSet dss = new DataSet();
Line 171: dss.ReadXml(Request.PhysicalApplicationPath + "data\\" + Request.Params["Name"] + ".xml");
Line 172:
Line 173: Session["userEmail"] = dss.Tables["Settings"].Rows[0]["Email"];
Line 174: Session["deleteFolder"] = dss.Tables["Settings"].Rows[0]["DeleteFolder"];
Line 175: Session["sentFolder"] = dss.Tables["Settings"].Rows[0]["SentFolder"];
Line 176:
Line 177: break;
Line 178: }
Line 179:
Line 180: Response.Redirect("inbox.aspx?Folder=Inbox");
Line 181: }
Line 182: catch(Exception x){
Line 183: if(!isConnected){
Line 184: m_ErrorText = x.Message;
Line 185: }
Line 186: m_errors= true;
Line 187: }
Line 188:
Line 189: clnt.Disconnect();
Line 190: }
Line 191: }
Line 192:
Line 193:
Line 194: #line default
Line 195: #line hidden
Line 196:
Line 197: public login_aspx() {
Line 198: System.Collections.ArrayList dependencies;
Line 199: if ((ASP.login_aspx.__initialized == false)) {
Line 200: ASP.login_aspx.__stringResource = System.Web.UI.TemplateControl.ReadStringResource(typeof(ASP.login_aspx));
Line 201: dependencies = new System.Collections.ArrayList();
Line 202: dependencies.Add("C:\\Inetpub\\wwwroot\\MailServer\\webmail\\login.aspx");
Line 203: ASP.login_aspx.__fileDependencies = dependencies;
Line 204: ASP.login_aspx.__initialized = true;
Line 205: }
Line 206: }
Line 207:
Line 208: protected override bool SupportAutoEvents {
Line 209: get {
Line 210: return false;
Line 211: }
Line 212: }
Line 213:
Line 214: protected System.Web.HttpApplication ApplicationInstance {
Line 215: get {
Line 216: return ((System.Web.HttpApplication)(this.Context.ApplicationInstance));
Line 217: }
Line 218: }
Line 219:
Line 220: public override string TemplateSourceDirectory {
Line 221: get {
Line 222: return "/mailserver/webmail";
Line 223: }
Line 224: }
Line 225:
Line 226: private void __BuildControlTree(System.Web.UI.Control __ctrl) {
Line 227: __ctrl.SetRenderMethodDelegate(new System.Web.UI.RenderMethod(this.__Render__control1));
Line 228: }
Line 229:
Line 230: private void __Render__control1(System.Web.UI.HtmlTextWriter __output, System.Web.UI.Control parameterContainer) {
Line 231: this.WriteUTF8ResourceString(__output, 0, 475, true);
Line 232:
Line 233: #line 148 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 234: Response.Write(Request.Params["Name"]);
Line 235:
Line 236: #line default
Line 237: #line hidden
Line 238: this.WriteUTF8ResourceString(__output, 475, 928, true);
Line 239:
Line 240: #line 173 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 241: Response.Write(m_WTxt["1"].ToUpper());
Line 242:
Line 243: #line default
Line 244: #line hidden
Line 245: __output.Write("\r\n  \r\n \r\n ");
Line 248:
Line 249: #line 176 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 250: Response.Write(m_WTxt["2"].ToUpper());
Line 251:
Line 252: #line default
Line 253: #line hidden
Line 254: __output.Write("
\r\n  \r\n \r\n ");
Line 257:
Line 258: #line 179 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 259: Response.Write(m_WTxt["3"].ToUpper());
Line 260:
Line 261: #line default
Line 262: #line hidden
Line 263: __output.Write("
\r\n  \r\n \r\n ");
Line 266:
Line 267: #line 182 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 268: Response.Write(m_WTxt["4"].ToUpper());
Line 269:
Line 270: #line default
Line 271: #line hidden
Line 272: __output.Write("
\r\n  \r\n \r\n ");
Line 275:
Line 276: #line 185 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 277: Response.Write(m_WTxt["5"].ToUpper());
Line 278:
Line 279: #line default
Line 280: #line hidden
Line 281: this.WriteUTF8ResourceString(__output, 1403, 707, true);
Line 282:
Line 283: #line 197 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 284: if(m_errors){
Line 285:
Line 286: #line default
Line 287: #line hidden
Line 288: __output.Write(" \t\r\n

 

\r\n

");
Line 290:
Line 291: #line 199 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 292: if(m_ErrorText.Length == 0){ Response.Write(m_WTxt["50"]); } else { Response.Write(m_ErrorText); }
Line 293:
Line 294: #line default
Line 295: #line hidden
Line 296: __output.Write("

\r\n

 

\r\n ");
Line 297:
Line 298: #line 201 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 299: }
Line 300:
Line 301: #line default
Line 302: #line hidden
Line 303: __output.Write("\r\n \r\n <tr" +
line="" 305:="" "="">\r\n
");
Line 306:
Line 307: #line 204 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 308: Response.Write(m_WTxt["6"]);
Line 309:
Line 310: #line default
Line 311: #line hidden
Line 312: this.WriteUTF8ResourceString(__output, 2110, 259, true);
Line 313:
Line 314: #line 210 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 315: Response.Write(m_WTxt["7"]);
Line 316:
Line 317: #line default
Line 318: #line hidden
Line 319: this.WriteUTF8ResourceString(__output, 2369, 393, true);
Line 320:
Line 321: #line 219 "C:\Inetpub\wwwroot\MailServer\webmail\login.aspx"
Line 322: Response.Write(m_WTxt["15"]);
Line 323:
Line 324: #line default
Line 325: #line hidden
Line 326: this.WriteUTF8ResourceString(__output, 2762, 890, true);
Line 327: }
Line 328:
Line 329: protected override void FrameworkInitialize() {
Line 330: SetStringResourcePointer(ASP.login_aspx.__stringResource, 3652);
Line 331: this.__BuildControlTree(this);
Line 332: this.FileDependencies = ASP.login_aspx.__fileDependencies;
Line 333: this.EnableViewStateMac = true;
Line 334: this.Request.ValidateInput();
Line 335: }
Line 336:
Line 337: public override int GetTypeHashCode() {
Line 338: return 857126699;
Line 339: }
Line 340: }
Line 341: }
Line 342:



If I just use the webmail directory and put that under inetpub\wwwroot I get the login page, but when I try to log in it says: No connection could be made because the target machine actively refused it.

I set up al of the SQL Server tables and stored procedures. I set up a login both in the users table and also within the mail manager. I set up the mail server and it is running fine. Any ideas on this?

Regards,

Dinesh

P.S. This is a great example keep up the good work

GeneralRe: trying to implement webmail Pin
heliosphan10-Aug-04 9:12
heliosphan10-Aug-04 9:12 
QuestionHow many mail servers can run in the same service? Pin
lvenlee4-Aug-04 21:47
susslvenlee4-Aug-04 21:47 
AnswerRe: How many mail servers can run in the same service? Pin
Anonymous5-Aug-04 18:38
Anonymous5-Aug-04 18:38 
GeneralRe: How many mail servers can run in the same service? Pin
eplanet8-Aug-04 8:37
eplanet8-Aug-04 8:37 
GeneralRe: How many mail servers can run in the same service? Pin
Anonymous8-Aug-04 18:36
Anonymous8-Aug-04 18:36 
GeneralRe: How many mail servers can run in the same service? Pin
eplanet8-Aug-04 19:31
eplanet8-Aug-04 19:31 
GeneralMX Record Query Problem Pin
Jeff Giasson8-Jul-04 5:10
sussJeff Giasson8-Jul-04 5:10 
GeneralRe: MX Record Query Problem Pin
Anonymous9-Jul-04 6:10
Anonymous9-Jul-04 6:10 
GeneralRe: MX Record Query Problem Pin
Anonymous10-Jul-04 21:19
Anonymous10-Jul-04 21:19 
GeneralConversion from Image to Text... Pin
NC Hal18-Jun-04 6:12
NC Hal18-Jun-04 6:12 
Questionis there have the issue time of the future release? Pin
Ivan Lee (CN)26-Apr-04 20:00
Ivan Lee (CN)26-Apr-04 20:00 
AnswerRe: is there have the issue time of the future release? Pin
Ivar Lumi26-Apr-04 20:05
Ivar Lumi26-Apr-04 20:05 
GeneralRe: is there have the issue time of the future release? Pin
Ivan Lee (CN)26-Apr-04 20:58
Ivan Lee (CN)26-Apr-04 20:58 
GeneralRe: is there have the issue time of the future release? Pin
Ivar Lumi26-Apr-04 21:04
Ivar Lumi26-Apr-04 21:04 
GeneralRe: is there have the issue time of the future release? Pin
Ivan Lee (CN)21-May-04 15:48
Ivan Lee (CN)21-May-04 15:48 
GeneralRe: is there have the issue time of the future release? Pin
Anonymous21-May-04 21:01
Anonymous21-May-04 21:01 
GeneralRe: is there have the issue time of the future release? Pin
lvenlee25-Jul-04 20:28
susslvenlee25-Jul-04 20:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.