![]() |
|
|
#1 |
|
Guest
Posts: n/a
|
Exception SmtpClient
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Re: Exception SmtpClient
In article <E8487E55-E313-4BB8-B076-C942ABF3DA61@microsoft.com>,
Torsten@discussions.microsoft.com says... > 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!! 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... -- Patrick Steele (patrick@mvps.org) http://weblogs.asp.net/psteele |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Re: Exception SmtpClient
One thing is that there are 3 different authentication modes for smtp.
None Basic SSL http://sholliday.spaces.live.com/Blo...842A!138.entry Get the sample download code there. There is 1.1 and 2.0 code available. "Torsten" <Torsten@discussions.microsoft.com> wrote in message news:E8487E55-E313-4BB8-B076-C942ABF3DA61@microsoft.com... > 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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Re: Exception SmtpClient
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 "Patrick Steele" wrote: > In article <E8487E55-E313-4BB8-B076-C942ABF3DA61@microsoft.com>, > Torsten@discussions.microsoft.com says... > > 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!! > > 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... > > -- > Patrick Steele (patrick@mvps.org) > http://weblogs.asp.net/psteele > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Re: Exception SmtpClient
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 "sloan" wrote: > One thing is that there are 3 different authentication modes for smtp. > > None > Basic > SSL > > http://sholliday.spaces.live.com/Blo...842A!138.entry > > Get the sample download code there. > > There is 1.1 and 2.0 code available. > > > > > "Torsten" <Torsten@discussions.microsoft.com> wrote in message > news:E8487E55-E313-4BB8-B076-C942ABF3DA61@microsoft.com... > > 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 > > > |
|
|
|
#6 |
|
Guest
Posts: n/a
|
Re: Exception SmtpClient
In article <EE0627E5-F603-4E7A-9EB8-CB3067E261AA@microsoft.com>,
Torsten@discussions.microsoft.com says... > 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? -- Patrick Steele (patrick@mvps.org) http://weblogs.asp.net/psteele |
|
|
|
#7 |
|
Guest
Posts: n/a
|
Re: Exception SmtpClient
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? "Patrick Steele" wrote: > In article <EE0627E5-F603-4E7A-9EB8-CB3067E261AA@microsoft.com>, > Torsten@discussions.microsoft.com says... > > 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? > > -- > Patrick Steele (patrick@mvps.org) > http://weblogs.asp.net/psteele > |
|
|
|
#8 |
|
Guest
Posts: n/a
|
Re: Exception SmtpClient
In article <22514203-FC07-4074-9D40-22A1D9D307C9@microsoft.com>,
Torsten@discussions.microsoft.com says... > 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. -- Patrick Steele (patrick@mvps.org) http://weblogs.asp.net/psteele |
|
|
|
#9 |
|
Newbie
Join Date: May 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
![]() |
Re: Exception SmtpClient
Torsten,
Did you resolve this and if so, what did you do? I have a very similar situation. Thank you. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SelectSingleNode throwing exception: | Anup Daware | C#(C Sharp) | 1 | 05-09-2007 03:44 PM |
| IE Exception and runtime errors | achiomo | Internet Explorer | 1 | 29-08-2007 07:20 AM |
| IE6 and IE7 - Proxy exception list BUG? | Alpha_Star | Internet Explorer | 0 | 29-08-2007 06:27 AM |
| IE6 and IE7 - Proxy exception list BUG? | Alpha_Star | Internet Explorer | 0 | 29-08-2007 06:23 AM |
| Shell32.dll exception | Cliff Lewis | Windows XP | 2 | 16-08-2007 12:37 PM |