473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Sep 4 '07 #1
6 5469
In article <E8**********************************@microsoft.co m>,
To*****@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 (pa*****@mvps.org)
http://weblogs.asp.net/psteele
Sep 5 '07 #2
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.


"Torsten" <To*****@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.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

Sep 5 '07 #3
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 <E8**********************************@microsoft.co m>,
To*****@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 (pa*****@mvps.org)
http://weblogs.asp.net/psteele
Sep 5 '07 #4
In article <EE**********************************@microsoft.co m>,
To*****@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 (pa*****@mvps.org)
http://weblogs.asp.net/psteele
Sep 7 '07 #5
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 <EE**********************************@microsoft.co m>,
To*****@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 (pa*****@mvps.org)
http://weblogs.asp.net/psteele
Sep 7 '07 #6
In article <22**********************************@microsoft.co m>,
To*****@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 (pa*****@mvps.org)
http://weblogs.asp.net/psteele
Sep 9 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: nitramsen | last post by:
Hi, I have been using SmtpClient but it seams that it is pretty hard on the SMTP servers it is sending to as it does not send a QUIT command and just closes the socket while the server is wait...
2
by: HK | last post by:
In VB.NET, I'm getting the exception "failure sending mail". I'm running VS 2005 on XP Home. This is a new install on a new PC. I've never had email problems with VS 2003, and there I could...
2
by: mensuur | last post by:
hi, i have an exception in my code for a contact form: protected void SendMessage_Click(object sender, EventArgs e) { MailMessage msg = new MailMessage(); msg.From = new...
6
by: theWizard1 | last post by:
Using VisualStudio 2005, asp.net 2.0: What do I put in my Web.Config to avoid hard coding the: myserveraddress.com? The following shows how I have hard coded it without having the value in the...
2
by: fhtino | last post by:
Hello, I'm trying to create an email message with particular headers. A piece of code: SmtpClient smtp = new SmtpClient("192.168.x.y"); MailMessage msg = new MailMessage("from@xxxxxxx",...
10
by: David Thole | last post by:
Hey all, I'm still very new at all this, but am going through the ASP.net 2.0 unleashed book, first chapter and trying to program my own little form emailer for fun. I tried following the code...
0
by: =?Utf-8?B?RnJlZHJpayBKb2hhbnNzb24=?= | last post by:
Hello, It seems like SmtpClient.EnableSsl = true, results in that the SmtpClient instance tries to use TLS over SMTP... That is: it commands "STARTTLS" when the connection has been established....
1
by: les | last post by:
I'm getting this error "BC30456: 'IsBodyHtml' is not a member of 'System.Net.Mail.SmtpClient'" when trying to submit a form and send email. If I remove the line "MailObj.IsBodyHtml = True" the...
2
by: btcoder | last post by:
Hi, my jsp page uses sun.net.smtp.SmtpClient to send email. It worked fine until the hosted location was moved to another server. Now it generates the sun.net.smtp.SmtpProtocolException and the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.