public static SmtpServer CreateAndBind(IPAddress serverListenAddress, int port) { var smtpServer = new SmtpServer(); smtpServer.BindAndListenTo(serverListenAddress, port); return(smtpServer); }
public SmtpConnection(SmtpServer server, PortListener portBinding, TcpClient tcpClient) : base(portBinding, tcpClient) { if (server == null) throw new ArgumentNullException("server"); Server = server; }
public static SmtpServer CreateAndBind(IPAddress serverListenAddress, int port) { var smtpServer = new SmtpServer(); smtpServer.BindAndListenTo(serverListenAddress, port); return smtpServer; }
public void SmtpServer_should_be_able_to_receive_mail_from_SmtpClient() { var mockEmailValidator = new Mock<IEmailValidator>(); mockEmailValidator.Setup(x => x.Validate(It.IsAny<string>())).Returns(true); var testPort = TestHelpers.GetTestPort(); var mailDataCollector = new TestMailDataCollector(); using (var smtpServer = new SmtpServer()) { var responderFactory = new SmtpResponderFactory(smtpServer.Configuration, mockEmailValidator.Object) { DataResponder = mailDataCollector }; smtpServer.DefaultResponderFactory = responderFactory; smtpServer.BindAndListenTo(IPAddress.Loopback, testPort); var sendMailTask = Task.Factory.StartNew(() => SendMail(testPort, "*****@*****.**", "*****@*****.**", "subject", "body"), TaskCreationOptions.LongRunning); Assert.True(sendMailTask.Wait(3000)); mockEmailValidator.Verify(x => x.Validate("*****@*****.**")); mockEmailValidator.Verify(x => x.Validate("*****@*****.**")); var mailData = mailDataCollector.MailData; Assert.Contains("*****@*****.**", mailData); Assert.Contains("*****@*****.**", mailData); Assert.Contains("subject", mailData); Assert.Contains("body", mailData); } }
public SmtpConnection(SmtpServer server, PortListener portBinding, TcpClient tcpClient) : base(portBinding, tcpClient) { if (server == null) { throw new ArgumentNullException("server"); } Server = server; }
private static SmtpServer StartSmtpServer() { var smtpServer = new SmtpServer { Configuration = { DefaultGreeting = "Simple.MailServer Example" } }; smtpServer.DefaultResponderFactory = new SmtpResponderFactory(smtpServer.Configuration) { DataResponder = new ExampleDataResponder(smtpServer.Configuration, RootMailDir) // ... inject other responders here as needed (or leave default) }; smtpServer.BindAndListenTo(IPAddress.Loopback, 25); return smtpServer; }
public void SmtpServer_should_be_able_to_receive_mail_from_SmtpClient() { var testPort = GetTestPort(); var mailDataCollector = new TestMailDataCollector(); using (var smtpServer = new SmtpServer()) { var responderFactory = new DefaultSmtpResponderFactory<ISmtpServerConfiguration>(smtpServer.Configuration) { DataResponder = mailDataCollector }; smtpServer.DefaultResponderFactory = responderFactory; smtpServer.BindAndListenTo(IPAddress.Loopback, testPort); var sendMailTask = Task.Factory.StartNew(() => SendMail(testPort, "*****@*****.**", "*****@*****.**", "subject", "body"), TaskCreationOptions.LongRunning); Assert.True(sendMailTask.Wait(1500)); var mailData = mailDataCollector.MailData; Assert.Contains("*****@*****.**", mailData); Assert.Contains("*****@*****.**", mailData); Assert.Contains("subject", mailData); Assert.Contains("body", mailData); } }