0

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);
    }
Joe Park
  • 77
  • 1
  • 6
  • Might be related: http://stackoverflow.com/questions/9779856/cannot-send-smtp-email-from-windows-service-on-win7 – David Brabant Aug 06 '14 at 07:01
  • David, Thanks for the comment. It's similar, but there are a few differences. The SMTP server in my case hosted in the same local machine. (fake SMTP java version). and I haven't seen any exception on the client side. – Joe Park Aug 06 '14 at 07:20
  • Addition: This works fine in windows 2008 server. – Joe Park Aug 07 '14 at 04:29

0 Answers0