Click here to Skip to main content
15,397,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am working on getting our development staff upgraded to Windows 7 from windows XP. I am having an issue with sending emails from my ASP.NET web application, which runs fine in XP/IIS 6. When running the web application on Windows 7 I keep getting a timeout error: "System.Net.Mail.SmtpException: The operation has timed out" however the email will eventually be delivered ~5 minutes later.

Here is the code I use to send the email:
C#
SmtpClient client = new SmtpClient();
client.Host = "SMTP.domain.xyz";
client.Port = 25;
client.ServicePoint.MaxIdleTime = 1;

MailMessage message = new MailMessage();
message.To.Add(new MailAddress("myaddress@myemail.com"));
message.From = new MailAddress("fromaddress@myemail.com");
message.Subject = "Test Email";
message.Body = "Here is the email";
client.Send(message);


The above code works fine if I put it in a Command Line application or a Windows Forms application. I think it is something to do with IIS but I cannot for the life of me figure it out.

I've added some diagnostics to the web.config and it gives the following:
System.Net Information: 0 : [6860] Current OS installation type is 'Client'.
System.Net Verbose: 0 : [7748] SmtpClient::.ctor()
System.Net Information: 0 : [7748] Associating SmtpClient#41622463 with SmtpTransport#31364015
System.Net Verbose: 0 : [7748] Exiting SmtpClient::.ctor() 	-> SmtpClient#41622463
System.Net Information: 0 : [7748] Associating MailMessage#28379535 with Message#64109423
System.Net Verbose: 0 : [7748] SmtpClient#41622463::Send(MailMessage#28379535)
System.Net Information: 0 : [7748] SmtpClient#41622463::Send(DeliveryMethod=Network)
System.Net Information: 0 : [7748] Associating SmtpClient#41622463 with MailMessage#28379535
System.Net Information: 0 : [7748] Associating SmtpTransport#31364015 with SmtpConnection#21943666
System.Net Information: 0 : [7748] Associating SmtpConnection#21943666 with ServicePoint#53052340
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Socket() 
System.Net.Sockets Verbose: 0 : [7748] Socket#46228029::Socket(InterNetworkV6#23)
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#46228029::Socket() 
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Connect(48:25#813428447)
System.Net.Sockets Information: 0 : [7748] Socket#5896758 - Created connection from 127.0.0.1:52182 to 198.238.123.48:25.
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Connect() 
System.Net.Sockets Verbose: 0 : [7748] Socket#46228029::Close()
System.Net.Sockets Verbose: 0 : [7748] Socket#46228029::Dispose()
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#46228029::Close() 
System.Net Information: 0 : [7748] SmtpPooledStream#49129953 - Created connection from 127.0.0.1:52182 to 198.238.123.48:25.
System.Net Information: 0 : [7748] Associating SmtpConnection#21943666 with SmtpPooledStream#49129953
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Receive()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Receive
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 32 32 30 20 6F 69 63 31-6D 78 6F 6C 79 30 31 2E : 220 servername.
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 6F 69 63 31 2E 77 61 2E-6C 63 6C 20 4D 69 63 72 : domain.xxx.xxx Micr
System.Net.Sockets Verbose: 0 : [7748] 00000020 : 6F 73 6F 66 74 20 45 53-4D 54 50 20 4D 41 49 4C : osoft ESMTP MAIL
System.Net.Sockets Verbose: 0 : [7748] 00000030 : 20 53 65 72 76 69 63 65-2C 20 56 65 72 73 69 6F :  Service, Versio
System.Net.Sockets Verbose: 0 : [7748] 00000040 : 6E 3A 20 36 2E 30 2E 33-37 39 30 2E 34 36 37 35 : n: 6.0.3790.4675
System.Net.Sockets Verbose: 0 : [7748] 00000050 : 20 72 65 61 64 79 20 61-74 20 20 4D 6F 6E 2C 20 :  ready at  Mon, 
System.Net.Sockets Verbose: 0 : [7748] 00000060 : 32 32 20 4F 63 74 20 32-30 31 32 20 30 39 3A 32 : 22 Oct 2012 09:2
System.Net.Sockets Verbose: 0 : [7748] 00000070 : 30 3A 33 32 20 2D 30 37-30 30 20 0D 0A          : 0:32 -0700 ..
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Receive() 	-> 125#125
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Send()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Send
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 45 48 4C 4F 20 4F 49 43-57 4B 44 30 32 39 37 33 : EHLO workstationname
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 0D 0A                                           : ..
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Send() 	-> 18#18
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Receive()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Receive
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 32 35 30 2D 6F 69 63 31-6D 78 6F 6C 79 30 31 2E : 250-servername.
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 6F 69 63 31 2E 77 61 2E-6C 63 6C 20 48 65 6C 6C : domain.xxx.xxx Hell
System.Net.Sockets Verbose: 0 : [7748] 00000020 : 6F 20 5B 31 39 38 2E 32-33 38 2E 32 35 32 2E 31 : o [198.238.252.1
System.Net.Sockets Verbose: 0 : [7748] 00000030 : 30 36 5D 0D 0A 32 35 30-2D 54 55 52 4E 0D 0A 32 : 06]..250-TURN..2
System.Net.Sockets Verbose: 0 : [7748] 00000040 : 35 30 2D 53 49 5A 45 0D-0A 32 35 30 2D 45 54 52 : 50-SIZE..250-ETR
System.Net.Sockets Verbose: 0 : [7748] 00000050 : 4E 0D 0A 32 35 30 2D 50-49 50 45 4C 49 4E 49 4E : N..250-PIPELININ
System.Net.Sockets Verbose: 0 : [7748] 00000060 : 47 0D 0A 32 35 30 2D 44-53 4E 0D 0A 32 35 30 2D : G..250-DSN..250-
System.Net.Sockets Verbose: 0 : [7748] 00000070 : 45 4E 48 41 4E 43 45 44-53 54 41 54 55 53 43 4F : ENHANCEDSTATUSCO
System.Net.Sockets Verbose: 0 : [7748] 00000080 : 44 45 53 0D 0A 32 35 30-2D 38 62 69 74 6D 69 6D : DES..250-8bitmim
System.Net.Sockets Verbose: 0 : [7748] 00000090 : 65 0D 0A 32 35 30 2D 42-49 4E 41 52 59 4D 49 4D : e..250-BINARYMIM
System.Net.Sockets Verbose: 0 : [7748] 000000A0 : 45 0D 0A 32 35 30 2D 43-48 55 4E 4B 49 4E 47 0D : E..250-CHUNKING.
System.Net.Sockets Verbose: 0 : [7748] 000000B0 : 0A 32 35 30 2D 56 52 46-59 0D 0A 32 35 30 2D 58 : .250-VRFY..250-X
System.Net.Sockets Verbose: 0 : [7748] 000000C0 : 2D 45 58 50 53 20 47 53-53 41 50 49 20 4E 54 4C : -EXPS GSSAPI NTL
System.Net.Sockets Verbose: 0 : [7748] 000000D0 : 4D 20 4C 4F 47 49 4E 0D-0A 32 35 30 2D 58 2D 45 : M LOGIN..250-X-E
System.Net.Sockets Verbose: 0 : [7748] 000000E0 : 58 50 53 3D 4C 4F 47 49-4E 0D 0A 32 35 30 2D 41 : XPS=LOGIN..250-A
System.Net.Sockets Verbose: 0 : [7748] 000000F0 : 55 54 48 20 47 53 53 41-50 49 20 4E 54 4C 4D 20 : UTH GSSAPI NTLM 
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Receive() 	-> 256#256
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Receive()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Receive
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 4C 4F 47 49 4E 0D 0A 32-35 30 2D 41 55 54 48 3D : LOGIN..250-AUTH=
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 4C 4F 47 49 4E 0D 0A 32-35 30 2D 58 2D 4C 49 4E : LOGIN..250-X-LIN
System.Net.Sockets Verbose: 0 : [7748] 00000020 : 4B 32 53 54 41 54 45 0D-0A 32 35 30 2D 58 45 58 : K2STATE..250-XEX
System.Net.Sockets Verbose: 0 : [7748] 00000030 : 43 48 35 30 0D 0A 32 35-30 20 4F 4B 0D 0A       : CH50..250 OK..
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Receive() 	-> 62#62
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Send()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Send
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 4D 41 49 4C 20 46 52 4F-4D 3A 3C 43 41 50 65 72 : MAIL FROM:<email>
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 40 6F 69 63 2E 77 61 2E-67 6F 76 3E 0D 0A       : @domain.xxx>..
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Send() 	-> 30#30
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Receive()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Receive
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 32 35 30 20 32 2E 31 2E-30 20 43 41 50 65 72 40 : 250 2.1.0 email@
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 6F 69 63 2E 77 61 2E 67-6F 76 2E 2E 2E 2E 53 65 : domain.xxx....Se
System.Net.Sockets Verbose: 0 : [7748] 00000020 : 6E 64 65 72 20 4F 4B 0D-0A                      : nder OK..
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Receive() 	-> 41#41
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Send()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Send
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 52 43 50 54 20 54 4F 3A-3C 73 68 61 6E 65 66 40 : RCPT TO:<myemail@>
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 6F 69 63 2E 77 61 2E 67-6F 76 3E 0D 0A          : domain.xxx>..
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Send() 	-> 29#29
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Receive()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Receive
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 32 35 30 20 32 2E 31 2E-35 20 73 68 61 6E 65 66 : 250 2.1.5 myemail
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 40 6F 69 63 2E 77 61 2E-67 6F 76 20 0D 0A       : @domain.xxx ..
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Receive() 	-> 30#30
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Send()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Send
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 44 41 54 41 0D 0A                               : DATA..
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Send() 	-> 6#6
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Receive()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Receive
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 33 35 34 20 50 6C 65 61-73 65 20 73 74 61 72 74 : 354 Please start
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 20 6D 61 69 6C 20 69 6E-70 75 74 2E 0D 0A       :  mail input...
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Receive() 	-> 30#30
System.Net Information: 0 : [7748] HeaderCollection#10675717::Set(Content-Transfer-Encoding=base64)
System.Net Information: 0 : [7748] HeaderCollection#10675717::Set(Content-Transfer-Encoding=quoted-printable)
System.Net Information: 0 : [7748] Associating Message#64109423 with HeaderCollection#16754362
System.Net Information: 0 : [7748] HeaderCollection#16754362::Remove(Content-Type)
System.Net Information: 0 : [7748] HeaderCollection#16754362::Set(MIME-Version=1.0)
System.Net Information: 0 : [7748] HeaderCollection#16754362::Remove(Sender)
System.Net Information: 0 : [7748] HeaderCollection#16754362::Remove(Cc)
System.Net Information: 0 : [7748] HeaderCollection#16754362::Remove(Reply-To)
System.Net Information: 0 : [7748] HeaderCollection#16754362::Remove(Bcc)
System.Net Information: 0 : [7748] HeaderCollection#16754362::Get(MIME-Version)
System.Net Information: 0 : [7748] HeaderCollection#16754362::Get(From)
System.Net Information: 0 : [7748] HeaderCollection#16754362::Get(To)
System.Net Information: 0 : [7748] HeaderCollection#16754362::Get(Date)
System.Net Information: 0 : [7748] HeaderCollection#16754362::Get(Subject)
System.Net Information: 0 : [7748] HeaderCollection#10675717::Get(Content-Type)
System.Net Information: 0 : [7748] HeaderCollection#10675717::Get(Content-Transfer-Encoding)
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Send()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Send
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 4D 49 4D 45 2D 56 65 72-73 69 6F 6E 3A 20 31 2E : MIME-Version: 1.
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 30 0D 0A 46 72 6F 6D 3A-20 43 41 50 65 72 40 6F : 0..From: email@d
System.Net.Sockets Verbose: 0 : [7748] 00000020 : 69 63 2E 77 61 2E 67 6F-76 0D 0A 54 6F 3A 20 73 : omain.xxx..To: m
System.Net.Sockets Verbose: 0 : [7748] 00000030 : 68 61 6E 65 66 40 6F 69-63 2E 77 61 2E 67 6F 76 : yemail@domain.xxx
System.Net.Sockets Verbose: 0 : [7748] 00000040 : 0D 0A 44 61 74 65 3A 20-32 32 20 4F 63 74 20 32 : ..Date: 22 Oct 2
System.Net.Sockets Verbose: 0 : [7748] 00000050 : 30 31 32 20 30 39 3A 32-31 3A 35 33 20 2D 30 37 : 012 09:21:53 -07
System.Net.Sockets Verbose: 0 : [7748] 00000060 : 30 30 0D 0A 53 75 62 6A-65 63 74 3A 20 45 6D 61 : 00..Subject: Tes
System.Net.Sockets Verbose: 0 : [7748] 00000070 : 69 6C 20 66 72 6F 6D 20-53 49 4D 42 41 0D 0A 43 : t Email..C
System.Net.Sockets Verbose: 0 : [7748] 00000080 : 6F 6E 74 65 6E 74 2D 54-79 70 65 3A 20 74 65 78 : ontent-Type: tex
System.Net.Sockets Verbose: 0 : [7748] 00000090 : 74 2F 70 6C 61 69 6E 3B-20 63 68 61 72 73 65 74 : t/plain; charset
System.Net.Sockets Verbose: 0 : [7748] 000000A0 : 3D 75 73 2D 61 73 63 69-69 0D 0A 43 6F 6E 74 65 : =us-ascii..Conte
System.Net.Sockets Verbose: 0 : [7748] 000000B0 : 6E 74 2D 54 72 61 6E 73-66 65 72 2D 45 6E 63 6F : nt-Transfer-Enco
System.Net.Sockets Verbose: 0 : [7748] 000000C0 : 64 69 6E 67 3A 20 71 75-6F 74 65 64 2D 70 72 69 : ding: quoted-pri
System.Net.Sockets Verbose: 0 : [7748] 000000D0 : 6E 74 61 62 6C 65 0D 0A-0D 0A                   : ntable....
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Send() 	-> 218#218
System.Net Information: 0 : [7748] HeaderCollection#10675717::Get(Content-Transfer-Encoding)
System.Net Information: 0 : [7748] HeaderCollection#10675717::Get(Content-Transfer-Encoding)
System.Net Information: 0 : [7748] HeaderCollection#10675717::Get(Content-Transfer-Encoding)
System.Net Information: 0 : [7748] HeaderCollection#10675717::Get(Content-Transfer-Encoding)
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Send()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Send
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 48 65 72 65 20 69 73 20-74 68 65 20 65 6D 61 69 : Here is the emai
System.Net.Sockets Verbose: 0 : [7748] 00000010 : 6C                                              : l
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Send() 	-> 17#17
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Send()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Send
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 0D 0A                                           : ..
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Send() 	-> 2#2
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Send()
System.Net.Sockets Verbose: 0 : [7748] Data from Socket#5896758::Send
System.Net.Sockets Verbose: 0 : [7748] 00000000 : 0D 0A 2E 0D 0A                                  : .....
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Send() 	-> 5#5
System.Net.Sockets Verbose: 0 : [7748] Socket#5896758::Receive()
System.Net.Sockets Verbose: 0 : [4584] Socket#5896758::Dispose()
System.Net.Sockets Error: 0 : [7748] Exception in the Socket#5896758::Receive - A blocking operation was interrupted by a call to WSACancelBlockingCall
System.Net Verbose: 0 : [4584] SmtpPooledStream::Dispose #49129953
System.Net.Sockets Verbose: 0 : [7748] Exiting Socket#5896758::Receive() 	-> 0#0
System.Net Verbose: 0 : [4584] Exiting SmtpPooledStream::Dispose #49129953
System.Net Error: 0 : [7748] Exception in the SmtpClient#41622463::Send - Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall.
System.Net Error: 0 : [7748]    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.DataStopCommand.Send(SmtpConnection conn)
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
System.Net Verbose: 0 : [7748] Exiting SmtpClient#41622463::Send()</email>
Posted
Updated 22-Oct-12 9:57am
v2

Your going to have to break it down a little more by telneting into your mailserver from the machine your having trouble with, and sending a hand type email from the command prompt. You should see the error appear, and be able to read the message.

Don't use the backspace key, and get it right the first time.


telnet SMTP.domain.xyz 25

helo SMTP.domain.xyz

mail from: f@domain.com

rcpt to: t@domain.com
data
subject: -type-
.
quit

You can use the smtp exception class, to get more precise information on what's happening, I had to do these things last week to figure out why I could not send email to certain domains.


[smtp exception class^]
   
v2
As it turns out it was Symantec that was causing the timeout issue. When I disabled the POP3/SMTP scanner feature I could send emails through my local web. I still don't know why Symantec only causes problems with my website and not the Windows Forms application. I can only assume it has something to do with changes in how IIS 7.5 works with SMTP.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900