public void TestSameRecipientMultipleTimes() { hMailServer.Logging logging = SingletonProvider<Utilities>.Instance.GetApp().Settings.Logging; logging.AWStatsEnabled = true; logging.Enabled = true; if (File.Exists(logging.CurrentAwstatsLog)) File.Delete(logging.CurrentAwstatsLog); hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Connect(25); Assert.IsTrue(oSMTP.Receive().StartsWith("220")); oSMTP.Send("HELO test\r\n"); Assert.IsTrue(oSMTP.Receive().StartsWith("250")); oSMTP.Send("MAIL FROM: [email protected]\r\n"); Assert.IsTrue(oSMTP.Receive().StartsWith("250")); oSMTP.Send("RCPT TO: [email protected]\r\n"); Assert.IsTrue(oSMTP.Receive().StartsWith("250")); oSMTP.Send("RCPT TO: [email protected]\r\n"); Assert.IsTrue(oSMTP.Receive().StartsWith("250")); oSMTP.Disconnect(); }
public void TestTooManyInvalidCommandsAUTH() { hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp(); hMailServer.Settings settings = _settings; settings.DisconnectInvalidClients = true; settings.MaxNumberOfInvalidCommands = 3; SMTPClientSimulator sim = new SMTPClientSimulator(); sim.Connect(25); sim.Send("EHLO test.com\r\n"); for (int i = 1; i <= 6; i++) { try { sim.Send("AUTH LOGIN\r\n"); string result = sim.Receive(); if (result.Contains("Too many invalid commands")) return; if (i > 5) break; sim.Send("YWNhZGVtaWE=\r\n"); sim.Receive(); sim.Send("abc\r\n"); sim.Receive(); } catch (Exception) { if (i < 5) { Assert.Fail("Was disconnected prematurely."); } return; } } Assert.Fail("Wasn't disconnected"); }
public void TestRcptToSyntax() { hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Connect(25); Assert.IsTrue(oSMTP.Receive().StartsWith("220")); oSMTP.Send("HELO test\r\n"); Assert.IsTrue(oSMTP.Receive().StartsWith("250")); // A few tests of invalid syntax. Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: <*****@*****.**>\r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("RCPT TO: [email protected]>\r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("RCPT TO: <[email protected]\r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("RCPT TO <[email protected]\r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("RCPT TO<[email protected]\r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("RCPT TO: <*****@*****.**>\r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("RCPT TO: [email protected]\r\n").StartsWith("250")); oSMTP.Disconnect(); }
public void TestMailFromSyntaxValidation() { var account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Connect(25); Assert.IsTrue(oSMTP.Receive().StartsWith("220")); oSMTP.Send("HELO test\r\n"); Assert.IsTrue(oSMTP.Receive().StartsWith("250")); // A few tests of invalid syntax. Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: <[email protected]\r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: [email protected]>\r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: < [email protected] \r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: < \r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: > \r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: <[email protected]\r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM <*****@*****.**>\r\n").StartsWith("250")); Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM [email protected]\r\n").StartsWith("250")); // Valid syntax, < and > Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: <*****@*****.**>\r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: [email protected]\r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: [email protected] \r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM:[email protected]\r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM:<*****@*****.**>\r\n").StartsWith("250")); Assert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); oSMTP.Disconnect(); }
public void TestHelo() { SMTPClientSimulator oSimulator = new SMTPClientSimulator(); oSimulator.Connect(25); string sWelcome = oSimulator.Receive(); oSimulator.Send("HELO\r\n"); string sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("501")) throw new Exception("Invalid response to HELO"); oSimulator.Send("HELO \r\n"); sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("501")) throw new Exception("Invalid response to HELO"); oSimulator.Send("HELO TEST.COM\r\n"); sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("250")) throw new Exception("Invalid response to HELO"); oSimulator.Send("HELO TEST.COM\r\n"); sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("250")) throw new Exception("Invalid response to HELO"); oSimulator.Send("EHLO TEST.COM\r\n"); sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("250")) throw new Exception("Invalid response to HELO"); oSimulator.Send("EHLO TEST.COM\r\n"); sResponse = oSimulator.Receive(); if (!sResponse.StartsWith("250")) throw new Exception("Invalid response to HELO"); oSimulator.Disconnect(); }
public void TestTooManyInvalidCommandsTempError() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); for (int i = 0; i < 10; i++) SingletonProvider<Utilities>.Instance.AddAccount(_domain, string.Format("test{0}@test.com", i), "test"); hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp(); hMailServer.Settings settings = _settings; settings.DisconnectInvalidClients = true; settings.MaxNumberOfInvalidCommands = 5; settings.AntiSpam.GreyListingEnabled = true; SMTPClientSimulator sim = new SMTPClientSimulator(); sim.Connect(25); string res = sim.Receive(); sim.Send("EHLO test.com\r\n"); res = sim.Receive(); sim.Send("MAIL FROM: <*****@*****.**>\r\n"); res = sim.Receive(); for (int i = 1; i < 10; i++) { string address = string.Format("test{0}@test.com", i); sim.Send("RCPT TO: " + address + "\r\n"); res = sim.Receive(); Assert.AreEqual("451 Please try again later.\r\n", res); } sim.Disconnect(); }
public void TestTooManyInvalidCommandsHELO() { hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp(); hMailServer.Settings settings = _settings; settings.DisconnectInvalidClients = true; settings.MaxNumberOfInvalidCommands = 3; SMTPClientSimulator sim = new SMTPClientSimulator(); sim.Connect(25); for (int i = 1; i <= 6; i++) { sim.Send("HELO\r\n"); string result = sim.Receive(); if (result.Contains("Too many invalid commands")) break; if (i > 5) Assert.Fail(); } }