private void TestSendingEmail(MailMessage message_) { int port = PortHelper.GetPort(); var smtpServer = new DummySmtpServer(port); smtpServer.Start(); using (var client = new SmtpClient("localhost", port)) { client.Send(message_); } smtpServer.Stop(); AssertMailBag(smtpServer.ReceivedMails, message_); }
public void TestSendingMessageWithSmtpPassworthAuthentication() { var message = new MailMessage(TestMessage.From, TestMessage.To); message.Body = TestMessage.Body; message.Subject = TestMessage.Subject; message.To.Add(TestMessage.AdditionalTo); int port = PortHelper.GetPort(); var smtpServer = new DummySmtpServer(port); smtpServer.Start(); using (var client = new SmtpClient("localhost", port)) { client.Credentials = new NetworkCredential("*****@*****.**", "this-is-the-password"); client.Send(message); } smtpServer.Stop(); AssertMailBag(smtpServer.ReceivedMails, message); }
public void ExampleSmtpUnitUsage() { // Setup using (var mockServer = new DummySmtpServer(5000)) // Randomly picked port 5000 here, use whatever value you would normally. { mockServer.Start(); // Act SendEmail(); // Assert Assert.That(mockServer, Received.Mail(1)); Assert.That(mockServer, Received.Mail(1).From("*****@*****.**")); Assert.That(mockServer, Received.Mail(1).To("*****@*****.**")); Assert.That(mockServer, Received.Mail(1).Subject("example mail message")); Assert.That(mockServer, Received.Mail(1).BodyContains("lorem ipsum")); // Clean up mockServer.Stop(); } }