public void Send_with_Auth_Success_Test() { using (var server = new SmtpServerForUnitTest( address: IPAddress.Loopback, port: 2525, credentials: new[] { new NetworkCredential("*****@*****.**", "p@$$w0rd") })) { server.Start(); var client = new SmtpClient("localhost", 2525); client.Credentials = new NetworkCredential("*****@*****.**", "p@$$w0rd"); client.Send( "*****@*****.**", "[email protected],[email protected]", "[HELLO WORLD]", "Hello, World."); server.ReceivedMessages.Count().Is(1); var msg = server.ReceivedMessages.Single(); msg.MailFrom.Is("<*****@*****.**>"); msg.RcptTo.OrderBy(_ => _).Is("<*****@*****.**>", "<*****@*****.**>"); msg.From.Address.Is("*****@*****.**"); msg.To.Select(_ => _.Address).OrderBy(_ => _).Is("*****@*****.**", "*****@*****.**"); msg.CC.Count().Is(0); msg.Subject.Is("[HELLO WORLD]"); msg.Body.Is("Hello, World."); } }
public void SetUp() { var fixture = new Fixture(); _userName = fixture.Create <string>(); _smtpPassword = fixture.Create <string>(); _mailSignatureHelper = Substitute.For <IMailSignatureHelper>(); _mailSignatureHelper.ComposeMailSignature().Returns(""); var bootstrapper = new IntegrationTestBootstrapper(); var container = bootstrapper.ConfigureContainer(); _th = container.GetInstance <TestHelper>(); _th.InitTempFolder("SmtpEmailTest"); _tokenReplacer = new TokenReplacer(); _tokenReplacer.AddStringToken("ReplaceThis", "Replaced"); var serverIp = IPAddress.Loopback; _smtpPort = FindFreeTcpPort(); _mailServer = serverIp.ToString(); _smtpServer = new SmtpServerForUnitTest(serverIp, _smtpPort, new[] { new NetworkCredential(_userName, _smtpPassword) }); _smtpServer.Start(); }