I have a C# client using SmtpClient class to send a email, which normally works well.
But,it does not send email in certain condition.
The client side didn't throw exception at all. It just looks ok. But, the SMTP log showed as below.
250-AUTH LOGIN 250 Ok 04:31:35 PM - Client: MAIL FROM: 04:31:35 PM - Server: 250 Ok 04:31:35 PM - Client: RCPT TO: 04:31:35 PM - Server: 250 Ok 04:31:35 PM - Client: RSET 04:31:35 PM - Server: 250 Ok 04:32:35 PM - Server: 421 Timeout waiting for data from client.
contidions. 1. It worked when debugging in VS2012 2. It failed whend running it as windwos service in local machine.
This is the only difference I can find between success and failure case. The code used was
public void SendEmail(MailAddressCollection toAddresses, string fromAddress, string subject, string body)
{
string smtpHost = emailHost;
SmtpClient smtp = new SmtpClient(smtpHost);
smtp.Credentials = new System.Net.NetworkCredential(emailAccountId, emailAccountPassword);
MailMessage message = new MailMessage();
foreach (var toAddress in toAddresses)
{
message.To.Add(toAddress);
}
message.From = new MailAddress(fromAddress);
message.Subject = subject;
message.Body = body;
message.IsBodyHtml = isBodyHtml;
smtp.Send(message);
}