SMTPClient, authentication, and a slow SMTP server

J

Justin James

Hello -

I am seeing some truly odd behavior when trying to authenticate against an
SMTP server using the System.Net.MailMessage object to send email. In a
nutshell, the SMTPClient object is sending this double CRLF pattern before
receiving the responses to previous commands, and then immediately plowing
ahead with "AUTH login...". What ends up happening is that it then gets the
response from the double CRLF, which is not the result it expected for the
"AUTH login..." (despite eventually getting the right response, the Base64
encoded request for a password) and blows up.

Manually replaying this precise conversation via telnet to port 25 reveals
that the SMTP server is taking 1 - 2 seconds to respond to each command, so
what I need is a way to slow down the SMTPClient object's sending of commands.

Below is the trace from ASP.Net (I obscurbed some ASCII & Hex Codes for
security).

Any suggestions?

Thanks in advance!

J.Ja

System.Net Information: 0 : [2112]
HeaderCollection#2808346::Set(Content-Transfer-Encoding=base64)
System.Net Information: 0 : [2112] Associating MailMessage#14333193 with
Message#13009416
System.Net Information: 0 : [2112] Associating MailMessage#41728762 with
Message#2174563
System.Net Information: 0 : [2112] Associating Message#2174563 with
HeaderCollection#63062333
System.Net Information: 0 : [2112]
HeaderCollection#63062333::Add(Content-type=text/plain; format=flowed;
delsp=yes; charset="UTF-8")
System.Net Verbose: 0 : [2112] SmtpClient::.ctor()
System.Net Information: 0 : [2112] Associating SmtpClient#16868352 with
SmtpTransport#19420176
System.Net Verbose: 0 : [2112] Exiting SmtpClient::.ctor() ->
SmtpClient#16868352
System.Net Verbose: 0 : [2112] SmtpClient#16868352::Send(MailMessage#41728762)
System.Net Information: 0 : [2112]
SmtpClient#16868352::Send(DeliveryMethod=Network)
System.Net Information: 0 : [2112] Associating SmtpClient#16868352 with
MailMessage#41728762
System.Net Information: 0 : [2112] Associating SmtpTransport#19420176 with
SmtpConnection#26314214
System.Net Information: 0 : [2112] Associating SmtpConnection#26314214 with
ServicePoint#24914721
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Socket()
System.Net.Sockets Verbose: 0 : [2112]
Socket#51438283::Connect(77:25#1305788104)
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Connect()
System.Net Information: 0 : [2112] Associating SmtpConnection#26314214 with
SmtpPooledStream#15315213
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Receive()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Receive
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 32 32 30 20 61 74 6C 61-6E
74 65 63 68 2E 6E 65 : 220 XYZ.ne
System.Net.Sockets Verbose: 0 : [2112] 00000010 : 74 20 45 53 4D 54 50 20-53
65 72 76 65 72 20 72 : t ESMTP Server r
System.Net.Sockets Verbose: 0 : [2112] 00000020 : 65 61 64 79 0D 0A
: eady..
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Receive()
-> 38#38
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Send()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Send
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 45 48 4C 4F 20 6C 6A 77-65
62 32 0D 0A : EHLO abc..
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Send() ->
13#13
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Receive()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Receive
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 32 35 30 2D 61 74 6C 61-6E
74 65 63 68 2E 6E 65 : 250-XYZ.ne
System.Net.Sockets Verbose: 0 : [2112] 00000010 : 74 20 64 6F 6D 61 69 6E-20
6E 61 6D 65 20 73 68 : t domain name sh
System.Net.Sockets Verbose: 0 : [2112] 00000020 : 6F 75 6C 64 20 62 65 20-71
75 61 6C 69 66 69 65 : ould be qualifie
System.Net.Sockets Verbose: 0 : [2112] 00000030 : 64 20 6C 6A 77 65 62 32-0D
0A 32 35 30 2D 44 53 : d ljweb2..250-DS
System.Net.Sockets Verbose: 0 : [2112] 00000040 : 4E 0D 0A 32 35 30 2D 53-49
5A 45 20 31 32 35 38 : N..250-SIZE 1258
System.Net.Sockets Verbose: 0 : [2112] 00000050 : 32 39 31 32 0D 0A 32 35-30
2D 53 54 41 52 54 54 : 2912..250-STARTT
System.Net.Sockets Verbose: 0 : [2112] 00000060 : 4C 53 0D 0A 32 35 30 2D-41
55 54 48 20 4C 4F 47 : LS..250-AUTH LOG
System.Net.Sockets Verbose: 0 : [2112] 00000070 : 49 4E 20 50 4C 41 49 4E-20
43 52 41 4D 2D 4D 44 : IN PLAIN CRAM-MD
System.Net.Sockets Verbose: 0 : [2112] 00000080 : 35 20 44 49 47 45 53 54-2D
4D 44 35 20 47 53 53 : 5 DIGEST-MD5 GSS
System.Net.Sockets Verbose: 0 : [2112] 00000090 : 41 50 49 20 4D 53 4E 20-4E
54 4C 4D 0D 0A 32 35 : API MSN NTLM..25
System.Net.Sockets Verbose: 0 : [2112] 000000A0 : 30 2D 45 54 52 4E 0D 0A-32
35 30 2D 54 55 52 4E : 0-ETRN..250-TURN
System.Net.Sockets Verbose: 0 : [2112] 000000B0 : 0D 0A 32 35 30 2D 41 54-52
4E 0D 0A 32 35 30 2D : ..250-ATRN..250-
System.Net.Sockets Verbose: 0 : [2112] 000000C0 : 4E 4F 2D 53 4F 4C 49 43-49
54 49 4E 47 0D 0A 32 : NO-SOLICITING..2
System.Net.Sockets Verbose: 0 : [2112] 000000D0 : 35 30 2D 38 42 49 54 4D-49
4D 45 0D 0A 32 35 30 : 50-8BITMIME..250
System.Net.Sockets Verbose: 0 : [2112] 000000E0 : 2D 48 45 4C 50 0D 0A 32-35
30 2D 50 49 50 45 4C : -HELP..250-PIPEL
System.Net.Sockets Verbose: 0 : [2112] 000000F0 : 49 4E 49 4E 47 0D 0A 32-35
30 20 45 48 4C 4F 0D : INING..250 EHLO.
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Receive()
-> 256#256
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Receive()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Receive
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 0A
: .
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Receive()
-> 1#1
System.Net Verbose: 0 : [2112]
SmtpNegotiateAuthenticationModule#41488021::Authenticate()
System.Net Information: 0 : [2112] Enumerating security packages:
System.Net Information: 0 : [2112] Negotiate
System.Net Information: 0 : [2112] Kerberos
System.Net Information: 0 : [2112] NTLM
System.Net Information: 0 : [2112] Schannel
System.Net Information: 0 : [2112] Microsoft Unified Security Protocol
Provider
System.Net Information: 0 : [2112] WDigest
System.Net Information: 0 : [2112] DPA
System.Net Information: 0 : [2112] Digest
System.Net Information: 0 : [2112] MSN
System.Net Information: 0 : [2112] AcquireCredentialsHandle(package =
Negotiate, intent = Outbound, authdata = (string.empty)\[email protected])
System.Net Information: 0 : [2112] InitializeSecurityContext(credential =
System.Net.SafeFreeCredential_SECURITY, context = (null), targetName = ,
inFlags = Connection, InitIntegrity)
System.Net Information: 0 : [2112] InitializeSecurityContext(In-Buffer
length=0, Out-Buffer length=40, returned code=ContinueNeeded).
System.Net Verbose: 0 : [2112] Exiting
SmtpNegotiateAuthenticationModule#41488021::Authenticate()
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Send()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Send
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 41 55 54 48 20 67 73 73-61
70 69 20 54 6C 52 4D : AUTH gssapi TlRM
System.Net.Sockets Verbose: 0 : [2112] 00000010 : 54 56 4E 54 55 41 41 42-41
41 41 41 6C 34 49 49 : TVNTUAABAAAAl4II
System.Net.Sockets Verbose: 0 : [2112] 00000020 : 34 67 41 41 41 41 41 41-41
41 41 41 41 41 41 41 : 4gAAAAAAAAAAAAAA
System.Net.Sockets Verbose: 0 : [2112] 00000030 : 41 41 41 41 41 41 41 46-41
73 34 4F 41 41 41 41 : AAAAAAAFAs4OAAAA
System.Net.Sockets Verbose: 0 : [2112] 00000040 : 44 77 3D 3D 0D 0A
: Dw==..
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Send() ->
70#70
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Receive()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Receive
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 33 33 34 20 54 6C 52 4D-54
56 4E 54 55 41 41 43 : 334 TlRMTVNTUAAC
System.Net.Sockets Verbose: 0 : [2112] 00000010 : 41 41 41 41 41 41 41 41-41
44 41 41 41 41 43 44 : AAAAAAAAADAAAACD
System.Net.Sockets Verbose: 0 : [2112] 00000020 : 41 68 42 41 51 30 59 78-4E
44 49 30 51 6A 51 41 : AhBAQ0YxNDI0QjQA
System.Net.Sockets Verbose: 0 : [2112] 00000030 : 41 41 41 41 41 41 41 41-41
41 41 41 41 41 41 41 : AAAAAAAAAAAAAAAA
System.Net.Sockets Verbose: 0 : [2112] 00000040 : 41 41 41 41 0D 0A
: AAAA..
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Receive()
-> 70#70
System.Net Verbose: 0 : [2112]
SmtpNegotiateAuthenticationModule#41488021::Authenticate()
System.Net Information: 0 : [2112] InitializeSecurityContext(credential =
System.Net.SafeFreeCredential_SECURITY, context = 22ed78:1f178cc8, targetName
= , inFlags = Connection, InitIntegrity)
System.Net Information: 0 : [2112] InitializeSecurityContext(In-Buffer
length=48, Out-Buffer length=12128, returned code=Unsupported).
System.Net Verbose: 0 : [2112] Exiting
SmtpNegotiateAuthenticationModule#41488021::Authenticate()
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Send()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Send
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 0D 0A 0D 0A
: ....
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Send() -> 4#4
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Receive()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Receive
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 35 33 35 20 47 53 53 41-50
49 20 4E 54 4C 4D 20 : 535 GSSAPI NTLM
System.Net.Sockets Verbose: 0 : [2112] 00000010 : 66 6F 72 6D 61 74 20 65-72
72 6F 72 0D 0A : format error..
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Receive()
-> 30#30
System.Net Verbose: 0 : [2112]
SmtpLoginAuthenticationModule#62301924::Authenticate()
System.Net Verbose: 0 : [2112] Exiting
SmtpLoginAuthenticationModule#62301924::Authenticate()
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Send()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Send
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 41 55 54 48 20 6C 6F 67-69
6E 20 63 32 68 76 63 : AUTH login c2hvc
System.Net.Sockets Verbose: 0 : [2112] 00000010 : 77 77 73 5A 77 5A 70 77-47
70 68 62 77 56 7A 4C : EAAAAAAAAAAAAVzL
System.Net.Sockets Verbose: 0 : [2112] 00000020 : 6D 4E 77 62 51 3D 3D 0D-0A
: mNvbQ==..
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Send() ->
41#41
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Receive()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Receive
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 35 30 31 20 55 6E 6B 6E-6F
77 6E 20 63 6F 6D 6D : 501 Unknown comm
System.Net.Sockets Verbose: 0 : [2112] 00000010 : 61 6E 64 0D 0A
: and..
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Receive()
-> 21#21
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Send()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Send
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 4D 41 49 4C 20 46 52 4F-4D
3A 3C 73 68 6F 70 40 : MAIL FROM:<shop@
System.Net.Sockets Verbose: 0 : [2112] 00000010 : 6C 65 77 77 77 77 77 77-77
73 2E 63 6F 6D 3E 0D : abc.com>.
System.Net.Sockets Verbose: 0 : [2112] 00000020 : 0A
: .
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Send() ->
33#33
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Receive()
System.Net.Sockets Verbose: 0 : [2112] Data from Socket#51438283::Receive
System.Net.Sockets Verbose: 0 : [2112] 00000000 : 33 33 34 20 55 47 46 7A-63
33 64 76 63 6D 51 36 : 334 UGFzc3dvcmQ6
System.Net.Sockets Verbose: 0 : [2112] 00000010 : 0D 0A
: ..
System.Net.Sockets Verbose: 0 : [2112] Exiting Socket#51438283::Receive()
-> 18#18
System.Net Error: 0 : [2112] Exception in the SmtpClient#16868352::Send -
The server committed a protocol violation The server response was:
UGFzc3dvcmQ6
System.Net Error: 0 : [2112] at
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String
response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command,
String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,
MailAddressCollection recipients, String deliveryNotify,
SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
System.Net.Sockets Verbose: 0 : [2112] Socket#51438283::Dispose()
System.Net Verbose: 0 : [2112] Exiting SmtpClient#16868352::Send()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top