Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Exception SmtpClient

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Torsten - 04 Sep 2007 20:28 GMT
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
Patrick Steele - 05 Sep 2007 01:29 GMT
> Hi,
>
[quoted text clipped - 32 lines]
>
> Thank you for any hints!!

Hmmmm... I wonder if smtpClient.ServicePoint.CloseConnectionGroup()
would help?  I don't know if that's even something you *should* do, even
if it does work.  I was just poking around the docs...

Signature

Patrick Steele (patrick@mvps.org)
http://weblogs.asp.net/psteele

Torsten - 05 Sep 2007 06:46 GMT
Hi Patrick,

I found the CloseConnectionGroup method, too. But it needs an argument (name
of the con group). So it would be intresting if I could/should use this
method and where I can get the name of the group. Do you have further
information about this method?

Torsten

> > Hi,
> >
[quoted text clipped - 36 lines]
> would help?  I don't know if that's even something you *should* do, even
> if it does work.  I was just poking around the docs...
Patrick Steele - 07 Sep 2007 03:13 GMT
> I found the CloseConnectionGroup method, too. But it needs an argument (name
> of the con group). So it would be intresting if I could/should use this
> method and where I can get the name of the group. Do you have further
> information about this method?

Sorry, no.  I was just poking around the docs.  I still think your code
is doing things correctly and I can't imagine why a port is being left
open.

Does this happen only when you're running in the debugger?  What if you
run it outside the debugger?  What happens if you run it in Release vs.
Debug mode?

Signature

Patrick Steele (patrick@mvps.org)
http://weblogs.asp.net/psteele

Torsten - 07 Sep 2007 06:26 GMT
Thanks for your help, Patrick.
I tested without the debugger - but I tried release and debug code. There is
no Visual Studio installed on the machines. Do you think I should test it
from VS? This is a little bit tricky, because my laptop is not part of this
domain.
My idea with the open port comes from the behavior of the smtp server.
Telnet to port 25 should work always afaik. But after the exception of my
program, telnet is also refused by the server till the next reboot.
I found another thing - the virus scanner. On the machines run Symantec anti
virus corp ed. There is a smtp scanner integrated, too. Is it possible that
the problem is not really program<->smtp-server, but
program<->antivirus<->smtp-server? Any suggestions?

> > I found the CloseConnectionGroup method, too. But it needs an argument (name
> > of the con group). So it would be intresting if I could/should use this
[quoted text clipped - 8 lines]
> run it outside the debugger?  What happens if you run it in Release vs.
> Debug mode?
Patrick Steele - 09 Sep 2007 15:44 GMT
> I found another thing - the virus scanner. On the machines run Symantec anti
> virus corp ed. There is a smtp scanner integrated, too. Is it possible that
> the problem is not really program<->smtp-server, but
> program<->antivirus<->smtp-server? Any suggestions?

It's definitely a possibility.  I would disable the SMTP scanner and see
what happens.

Signature

Patrick Steele (patrick@mvps.org)
http://weblogs.asp.net/psteele

sloan - 05 Sep 2007 02:40 GMT
One thing is that there are 3 different authentication modes for smtp.

None
Basic
SSL

http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry

Get the sample download code there.

There is 1.1 and 2.0 code available.

> Hi,
>
[quoted text clipped - 40 lines]
>
> Torsten
Torsten - 05 Sep 2007 06:50 GMT
Hi Sloan,

Thanks for the link. I will have a look at it. But I don't think the problem
is about authentication. It works fine after rebooting (if there would be a
problem with authentication it should have never work). I tried the same
steps with the smtpClient.UseDefaultCredentials = true. The result was the
same. And I checked the exchange configuration - it does not need
authentication (it is a local server in the intranet and is not accessable
from the internet).

Torsten

> One thing is that there are 3 different authentication modes for smtp.
>
[quoted text clipped - 52 lines]
> >
> > Torsten

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.