G
Guest
Hi,
I have a problem sending mails with the SmtpClient class. It's strange -
after I boot the pc and start the program I can send mails many times. After
I close the program and start it again it sometimes works too, but often does
not. If it does not, he will never - until the next reboot. Then the "game"
starts again.
I get the exception "'No connection could be made because the target machine
actively refused it.". Telnet to port 25 will be refused too after this
happens the first time. After reboot telnet (and my program) works fine -
until the next error.
I use an internal mail server (ms exchange 2003) that is used by many other
programs - and they run fine. I tried it from diffrent clients but it is all
the same. My assumption is, that the connection is not closed properly and
the server refuses another (or too much) connections.
I tried to dispose the smtpclient after using it but it does not have a
..Dispose(). Because of that I cannot use using(). Is there another way to
check (or close) the connection?
Here the code:
SmtpClient smtpClient = new SmtpClient(config.MailServer);
smtpClient.UseDefaultCredentials = config.SmtpAuthentification;
string mailBody = "Sample Body";
foreach (string mailRecipient in config.MailRecipients)
{
using (MailMessage message = new
MailMessage(config.MailSender, mailRecipient))
{
message.Subject = "Sample Subject";
message.Body = mailBody;
smtpClient.Send(message);
}
}
Thank you for any hints!!
Torsten
I have a problem sending mails with the SmtpClient class. It's strange -
after I boot the pc and start the program I can send mails many times. After
I close the program and start it again it sometimes works too, but often does
not. If it does not, he will never - until the next reboot. Then the "game"
starts again.
I get the exception "'No connection could be made because the target machine
actively refused it.". Telnet to port 25 will be refused too after this
happens the first time. After reboot telnet (and my program) works fine -
until the next error.
I use an internal mail server (ms exchange 2003) that is used by many other
programs - and they run fine. I tried it from diffrent clients but it is all
the same. My assumption is, that the connection is not closed properly and
the server refuses another (or too much) connections.
I tried to dispose the smtpclient after using it but it does not have a
..Dispose(). Because of that I cannot use using(). Is there another way to
check (or close) the connection?
Here the code:
SmtpClient smtpClient = new SmtpClient(config.MailServer);
smtpClient.UseDefaultCredentials = config.SmtpAuthentification;
string mailBody = "Sample Body";
foreach (string mailRecipient in config.MailRecipients)
{
using (MailMessage message = new
MailMessage(config.MailSender, mailRecipient))
{
message.Subject = "Sample Subject";
message.Body = mailBody;
smtpClient.Send(message);
}
}
Thank you for any hints!!
Torsten