Hello folks!
I'm trying to send email using the new classes of .NET 2.0, with the following code:
MailMessage msg = new MailMessage();
msg.To.Add("bribeiro@certisign.com.br");
msg.From = new MailAddress("bribeiro@certisign.com.br", "Bruno Ribeiro", Encoding.UTF8);
msg.Subject = "Teste de envio de emails usando .NET 2.0";
msg.SubjectEncoding = Encoding.UTF8;
msg.Body = "Este e o corpo da mensagem.";
msg.BodyEncoding = Encoding.UTF8;
msg.IsBodyHtml = false;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("bribeiro@certisign.com.br", "xxx");
client.Port = 587;
client.Host = "smtp.certisign.com.br";
client.EnableSsl = true;
client.Send(msg);
Unfortunatelly I got a "Time out" exception. The System.Net tracing log is the following:
System.Net Information: 0 : [3260] Associating MailMessage#39785641 with Message#45523402
System.Net Verbose: 0 : [3260] SmtpClient::.ctor()
System.Net Information: 0 : [3260] Associating SmtpClient#35287174 with SmtpTransport#44419000
System.Net Verbose: 0 : [3260] Exiting SmtpClient::.ctor() -> SmtpClient#35287174
System.Net Verbose: 0 : [3260] SmtpClient#35287174::Send(MailMessage#39785641)
System.Net Information: 0 : [3260] SmtpClient#35287174::Send(DeliveryMethod=Network)
System.Net Information: 0 : [3260] Associating SmtpClient#35287174 with MailMessage#39785641
System.Net Information: 0 : [3260] Associating SmtpTransport#44419000 with SmtpConnection#52697953
System.Net Information: 0 : [3260] Associating SmtpConnection#52697953 with ServicePoint#22597652
System.Net Information: 0 : [3260] Associating SmtpConnection#52697953 with SmtpPooledStream#10261382
System.Net Error: 0 : [3260] Exception in the SmtpClient#35287174::Send - Unable to read data from the transport connection: Uma operacao de bloqueio foi interrompida por uma chamada a WSACancelBlockingCall.
System.Net Error: 0 : [3260] at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at System.Net.Mail.SmtpReplyReader.ReadLine()
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
System.Net Verbose: 0 : [3260] Exiting SmtpClient#35287174::Send()
Any ideas
Thanks for help!
Bruno.

Sending Email problem (.NET 2.0)
Dancer John
I tried to increase the timeout to 500000 (500 seconds). Same error :(
System.Net Information: 0 : [4188] Associating MailMessage#39785641 with Message#45523402
System.Net Verbose: 0 : [4188] SmtpClient::.ctor()
System.Net Information: 0 : [4188] Associating SmtpClient#35287174 with SmtpTransport#44419000
System.Net Verbose: 0 : [4188] Exiting SmtpClient::.ctor() -> SmtpClient#35287174
System.Net Verbose: 0 : [4188] SmtpClient#35287174::Send(MailMessage#39785641)
System.Net Information: 0 : [4188] SmtpClient#35287174::Send(DeliveryMethod=Network)
System.Net Information: 0 : [4188] Associating SmtpClient#35287174 with MailMessage#39785641
System.Net Information: 0 : [4188] Associating SmtpTransport#44419000 with SmtpConnection#52697953
System.Net Information: 0 : [4188] Associating SmtpConnection#52697953 with ServicePoint#22597652
System.Net Information: 0 : [4188] Associating SmtpConnection#52697953 with SmtpPooledStream#10261382
System.Net Error: 0 : [4188] Exception in the SmtpClient#35287174::Send - Unable to read data from the transport connection: Uma operacao de bloqueio foi interrompida por uma chamada a WSACancelBlockingCall.
System.Net Error: 0 : [4188] at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at System.Net.Mail.SmtpReplyReader.ReadLine()
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
System.Net Verbose: 0 : [4188] Exiting SmtpClient#35287174::Send()
Thank you!
Bruno.
AnilYu
Yes, I can connect via telnet, using the port 587.
By the way, I can connect using CDO classes, the problem just happens with this new .NET classes.
Thanks!
Roinka
Thanks!
Satyajit Mahapatra
Any firewalls, antivirus/antispyware blocking the port
Another thing: is this the complete log If not see the SSL certificates If not then you haven't been able to establish the SSL connection successfully. You'll need to use the CertificateValidationCallback and check for errors
Mariya
Raymond1980
I was testing using Etheral software, for inspect the network packages. It is strange, cause nothing goes out from my IP address to the SMTP server.
hyan
Sorry, I had a VPN software running on my workstation. I have turn off this, and got the following Ethereal log:
Source / Destination / Protocol / Info
192.168.11.241 / 192.168.5.30 / DNS / Standard query A smtp.certisign.com.br
192.168.5.30 / 192.168.11.241 / DNS / Standard query response A 200.225.81.134
192.168.11.241 / 200.225.81.134 / TCP / 1150 > 587 [SYN] Seq=0 Ack=0 Win=16384 Len=0 MSS=1460
200.225.81.134 / 192.168.11.241 / TCP / 587 > 1150 {SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1460
192.168.11.241 / 200.225.81.134 / TCP / 1150 > 587 [ACK] Seq=1 Ack=1 Win=17520 [CHECKSUM INCORRECT] Len=0
192.168.11.241 ==> my workstation
192.168.5.30 ==> DNS server
200.225.81.134 ==> smtp.certisign.com.br (my SMTP server).
Thanks!
bleu
I changed my code this way:
static private void SendMailWithDotNet20()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(RemoteServerCertificateValidationCallback);
SmtpClient client = new SmtpClient("smtp.certisign.com.br", 587);
client.EnableSsl = true;
MailAddress from = new MailAddress("bribeiro@certisign.com.br", "Bruno de Paula Ribeiro");
MailAddress to = new MailAddress("bribeiro@certisign.com.br", "Bruno de Paula Ribeiro");
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test e-mail message.";
message.Subject = "Test email with SSL and Credentials";
NetworkCredential myCreds = new NetworkCredential("bribeiro@certisign.com.br", "xxx", "");
client.Credentials = myCreds;
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception is:" + ex.ToString());
}
Console.WriteLine("Goodbye.");
Console.ReadLine();
}
public static bool RemoteServerCertificateValidationCallback(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
Console.WriteLine("Remote Server Cert validation callback called");
Console.WriteLine(sslPolicyErrors);
return sslPolicyErrors == SslPolicyErrors.None;
}
}
But the call back is never called. And the log remains the same.
I have antivirus and firewalls here, but I supose this is opened, cause my Outlook works well. I also can send emails using CDO classes.
Thanks!
BijuMelayil
Samie_ug
Do you have the RTM version of the framework We had a bug with SMTP in Beta2. Here is the thread on this:
http://forums.microsoft.com/msdn/showpost.aspx postid=7575&siteid=1
Mariya
Lidya
This is an example of what should be in the log if the negotiation succeeds.
[Subject]
CN=smtp.gmail.com, O=Google Inc, L=Mountain View, S=California, C=US
Simple Name: smtp.gmail.com
DNS Name: smtp.gmail.com
[Issuer]
E=premium-server@thawte.com, CN=Thawte Premium Server CA, OU=Certification Services Division, O=Thawte Consulting cc, L=Cape Town, S=Western Cape, C=ZA
Simple Name: Thawte Premium Server CA
Email Name: premium-server@thawte.com
DNS Name: Thawte Premium Server CA
If you don't have the server certificates the negotiation hasn't succeeded and you have nothing to validate in the callback. Try this:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
Mariya
Schtrudel
Tryt connecting via telnet onthe same computer
STart -> run -> cmd.exe
telnet smtp.certisign.com.br 25
And see if you can connect. Also if you're savvy then try to send an email message via telnet to see if it works.
Hope this helps.
Dpowers
The address "smtp.certisign.com.br" is only reachable from inside the company network.
If there is any test I can do using this address, please let me know.
Thanks!
Carlos_SS
Did you try increasing the timeout The default value is 100,000 (100 seconds).
Mariya
vino-msdba
I'll investigate if there is a problem with the international chars and let you know later today. Other than that I am not able to telnet to your SMTP server at all.
Mariya