public void QueueMessage() { using (CreateTransactionScopeObject()) { using (SmtpServer s = new SmtpServer(8000)) { TcpClient client = new TcpClient(); client.Connect(IPAddress.Parse("127.0.0.1"), 8000); SmtpStreamHandler smtp = new SmtpStreamHandler(client); Func <string, string, Task <bool> > sendLine = new Func <string, string, Task <bool> >(async delegate(string cmd, string expectedResponse) { await smtp.WriteLineAsync(cmd, false); string response = await smtp.ReadLineAsync(false); Console.WriteLine(cmd + " " + expectedResponse + " " + response); Assert.AreEqual(expectedResponse, response.Substring(0, 3)); return(true); }); Task.Run(new Action(async delegate() { await smtp.ReadLineAsync(); await sendLine("HELO localhost", "250"); await sendLine("MAIL FROM: <local@localhost>", "250"); await sendLine("RCPT TO: <*****@*****.**>", "250"); await sendLine("DATA", "354"); await smtp.WriteLineAsync("Hello", false); await sendLine(".", "250"); await smtp.WriteLineAsync("QUIT"); })).Wait(); } } }
public void SendMessage() { using (CreateTransactionScopeObject()) { using (SmtpServer s = new SmtpServer(8000)) { TcpClient client = new TcpClient(); client.Connect(IPAddress.Parse("127.0.0.1"), 8000); SmtpStreamHandler smtp = new SmtpStreamHandler(client); Action <string, string> sendLine = new Action <string, string>(delegate(string cmd, string expectedResponse) { smtp.WriteLine(cmd, false); string response = smtp.ReadLineAsync(false).Result; Console.WriteLine(cmd + " " + expectedResponse + " " + response); Assert.AreEqual(expectedResponse, response.Substring(0, 3)); }); string result = smtp.ReadLineAsync().Result; sendLine("HELO localhost", "250"); sendLine("MAIL FROM: <local@localhost>", "250"); sendLine("RCPT TO: <postmaster@localhost>", "250"); sendLine("DATA", "354"); smtp.WriteLine("Hello", false); sendLine(".", "250"); smtp.WriteLine("QUIT"); } } }
public void TestUnicode() { string unicodeStr = "को कथा"; using (MemoryStream ms = new MemoryStream()) { SmtpStreamHandler stream = new SmtpStreamHandler(ms); stream.SetSmtpTransportMIME(SmtpTransportMIME._8BitUTF); stream.WriteAsync(unicodeStr, false).Wait(); ms.Position = 0; string result = stream.ReadLineAsync(false).Result; Assert.AreEqual(unicodeStr, result); } using (MemoryStream ms = new MemoryStream()) { SmtpStreamHandler stream = new SmtpStreamHandler(ms); stream.SetSmtpTransportMIME(SmtpTransportMIME._7BitASCII); stream.WriteLine(unicodeStr, false); ms.Position = 0; string result = stream.ReadLineAsync(false).Result; Assert.AreNotEqual(unicodeStr, result); } }