Example #1
0
 static void Main(string[] args)
 {
     SimpleSmtpServer server= new SimpleSmtpServer();
     server.Start();
     while(true)
     {
         if (server.ReceivedEmailCount > 0)
         {
             foreach(SmtpMessage message in server.ReceivedEmail)
             {
                 Console.WriteLine("----------------------------------------------------------------");
                 Console.WriteLine();
                 Console.WriteLine(message.ToString());
             }
             server.ClearReceivedEmail();
         }
         Thread.Sleep(100);
     }
 }
 protected void setUp()
 {
     server = new SimpleSmtpServer();
     server.Start();
     server2 = null;
 }
        public void MultipleServerPort()
        {
            int ALT_PORT = 2525;

            // Start second server
            server2 = new SimpleSmtpServer(ALT_PORT);
            server2.Start();

            // Send to first server
            System.Web.Mail.SmtpMail.SmtpServer = "localhost";
            System.Web.Mail.SmtpMail.Send("*****@*****.**", "*****@*****.**", "This is the subject", "This is the body.");

            // Send to second server
            MailMessage mail = new MailMessage();
            mail.To = "*****@*****.**";
            mail.From = "*****@*****.**";
            mail.Subject = "This is the second subject";
            mail.Body = "This is the second body.";
            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", ALT_PORT.ToString());
            SmtpMail.Send(mail);

            // Check first server
            Assert.AreEqual(1, server.ReceivedEmail.Length, "server.ReceivedEmail.Length");
            Assert.AreEqual(1, server.ReceivedEmailCount, "server.ReceivedEmailSize");

            SmtpMessage email =  server.ReceivedEmail[0];

            Assert.AreEqual("<*****@*****.**>", email.Headers["To"]);
            Assert.AreEqual("<*****@*****.**>", email.Headers["From"]);

            Assert.AreEqual("text/plain;", email.Headers["Content-Type"]);

            Assert.AreEqual("This is the subject", email.Headers["Subject"]);
            Assert.AreEqual("This is the body.", email.Body);

            // Check second server
            Assert.AreEqual(1, server2.ReceivedEmail.Length, "server.ReceivedEmail.Length");
            Assert.AreEqual(1, server2.ReceivedEmailCount, "server.ReceivedEmailSize");

            SmtpMessage email1 =  server2.ReceivedEmail[0];

            Assert.AreEqual("<*****@*****.**>", email1.Headers["To"]);
            Assert.AreEqual("<*****@*****.**>", email1.Headers["From"]);

            Assert.AreEqual("text/plain;", email1.Headers["Content-Type"]);

            Assert.AreEqual("This is the second subject", email1.Headers["Subject"]);
            Assert.AreEqual("This is the second body.", email1.Body);
        }
        public void ServerBindingError()
        {
            // Server is already running. We check that this cause an SocketException to be thrown
            SimpleSmtpServer server2 = new SimpleSmtpServer();
            server2.Start();

            Assert.Fail("BindingError");
        }