I successfully used nDumbster in .NET 1.1 tests using System.Web.Mail a long time ago and would like to use it again for some simple tests for System.Net.Mail.
I'm having weird socket issues trying to run nDumbster with System.Net.Mail (with both Send and SendAsync) under ReSharper 4.1 and .NET 3.5. I always seem to hit a deadlock when trying access smtpServer.ReceivedEmailCount after the first test runs. I'm mostly using the example code for test cases where [SetUp] and [TearDown] Starts()s and Stop()s the server. The second test always hangs because of the lock(this) inside ReceivedEmailCount . I've also tried creating a single instance of the server in [TestFixtureSetUp] and calling ClearReceivedEmail in [SetUp].
I've also tried using the latest code from CVS. The WaitAfterCommands class is missing so I had to write my own:
public class WaitAfterCommands
{
public static WaitAfterCommands Instance = new WaitAfterCommands();
public int TcpConnectionSecs = 1; // ???
public int HeloCommandSecs = 0;
public int MailCommandSecs = 0;
public int RcptCommandSecs = 0;
public int DataCommandSecs = 0;
public int DataCompletionSecs = 1; // ???
}
Is nDumbster still being used by people? Are the mailing lists a better place to post questions?
Thanks,
Ron
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have seen the same problem and got a workground at least for single emails
The following test (returning in a second or so)
[TestMethod]
public void CanRecieveSingleWebMail()
{
System.Web.Mail.SmtpMail.SmtpServer = "localhost";
System.Web.Mail.SmtpMail.Send("somebody@foo.com", "everybody@bar.com", "This is the subject", "This is the body.");
Assert.AreEqual(1, smtpServer.ReceivedEmail.Length);
}
However the test using System.Net.Mail fails
[TestMethod]
public void CanRecieveSingleNetMail()
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("localhost");
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage("somebody@foo.com", "everybody@bar.com", "This is the subject", "This is the body.");
client.Send(msg);
Assert.AreEqual(1, smtpServer.ReceivedEmail.Length);
}
Take 100 seconds to return, after a bit of debugging I found the problem was the final input.ReadLine(); in HandleSmtpTranslation which we expect to get a null at the end of a message, for Systsem.Web.Mail this returns instantly, but for System.Net.Mail this takes 100 second, but then is fine. But the 100 second delay is a bit of a pain for TDD!
As a work round I have put in the logic of HandleSmtpTranslation
string line = null;
if (smtpState != SmtpState.QUIT)
{
line = input.ReadLine();
}
if (line == null)
{
break;
}
Both the above tests now work. However if you send more than one email in a batch (multiple sends) it works for System.Web.Mail but not for System.Net.Mail - the error now appears when the second maiil is sent saying the server is not there. I suspect a thread issue as I think System.Web.Mail was single threaded
Anyway hope this gets you going
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I successfully used nDumbster in .NET 1.1 tests using System.Web.Mail a long time ago and would like to use it again for some simple tests for System.Net.Mail.
I'm having weird socket issues trying to run nDumbster with System.Net.Mail (with both Send and SendAsync) under ReSharper 4.1 and .NET 3.5. I always seem to hit a deadlock when trying access smtpServer.ReceivedEmailCount after the first test runs. I'm mostly using the example code for test cases where [SetUp] and [TearDown] Starts()s and Stop()s the server. The second test always hangs because of the lock(this) inside ReceivedEmailCount . I've also tried creating a single instance of the server in [TestFixtureSetUp] and calling ClearReceivedEmail in [SetUp].
I've also tried using the latest code from CVS. The WaitAfterCommands class is missing so I had to write my own:
public class WaitAfterCommands
{
public static WaitAfterCommands Instance = new WaitAfterCommands();
public int TcpConnectionSecs = 1; // ???
public int HeloCommandSecs = 0;
public int MailCommandSecs = 0;
public int RcptCommandSecs = 0;
public int DataCommandSecs = 0;
public int DataCompletionSecs = 1; // ???
}
Is nDumbster still being used by people? Are the mailing lists a better place to post questions?
Thanks,
Ron
I have seen the same problem and got a workground at least for single emails
The following test (returning in a second or so)
[TestMethod]
public void CanRecieveSingleWebMail()
{
System.Web.Mail.SmtpMail.SmtpServer = "localhost";
System.Web.Mail.SmtpMail.Send("somebody@foo.com", "everybody@bar.com", "This is the subject", "This is the body.");
Assert.AreEqual(1, smtpServer.ReceivedEmail.Length);
}
However the test using System.Net.Mail fails
[TestMethod]
public void CanRecieveSingleNetMail()
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("localhost");
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage("somebody@foo.com", "everybody@bar.com", "This is the subject", "This is the body.");
client.Send(msg);
Assert.AreEqual(1, smtpServer.ReceivedEmail.Length);
}
Take 100 seconds to return, after a bit of debugging I found the problem was the final input.ReadLine(); in HandleSmtpTranslation which we expect to get a null at the end of a message, for Systsem.Web.Mail this returns instantly, but for System.Net.Mail this takes 100 second, but then is fine. But the 100 second delay is a bit of a pain for TDD!
As a work round I have put in the logic of HandleSmtpTranslation
string line = null;
if (smtpState != SmtpState.QUIT)
{
line = input.ReadLine();
}
if (line == null)
{
break;
}
Both the above tests now work. However if you send more than one email in a batch (multiple sends) it works for System.Web.Mail but not for System.Net.Mail - the error now appears when the second maiil is sent saying the server is not there. I suspect a thread issue as I think System.Web.Mail was single threaded
Anyway hope this gets you going
I ended up using this code:
http://www.lumisoft.ee/forum/default.aspx?g=posts&m=1494
Works great plus is a full server in case I need to do anything additional in the future.
Thanks that has really helped looks to do just the job