Today, I sent a mail to the mailbox smtpclient. The MailServer on the shelf is normal, but the MailServer on the other side is lost. It is found that the mailbox certificate appears, but the Outlook mail is normal, if no result is found, use the wireshark to check whether the smtpclient is different from the one sent by outlook. Finally, use reflector to find out how to set the authentication method.
This is an example of zookeeper.
Smtptest.rar
This is to capture the outlook Package content (the blacklist is that private information such as host and userid)
Yellow: text sent from the current Machine
Secondary color: The text returned by MailServer.
This is the packet content for capturing smtpclient.
It is found that auth outlock uses login (base64 encryption only), while smtpclient uses gssapi (online query is a type of Kerberos, win2000 (without upgrading SP2) ).
From this we can see that the reason for this is that the client's MailServer, using gssapi authentication will fail. How can we change the modify pclient method?
Before today, I only knew to use this method: smtpclient. Credentials = new networkcredential (usernametextbox. Text, passwordtextbox. Text );
Google did not find a way to change the credential, so he had to use reflector to see how he actually did it.
Note: The system. net. Mail naming space is omitted below.
It is found in the smtpconnection. getconnection method (reflector has no rows of response)
....
Networkcredential credential = This. Credentials. getcredential (host, port, this. authenticationmodules [I]. authenticationtype );
If (Credential! = NULL)
{
....
}
....
Determine the authentication method in this industry
Authenticationmodules depends on the ismtpauthenticationmodule modules column.
There are four members
Smtpnegotiateauthenticationmodule authenticationtype = gssapi
Smtpntlmauthenticationmodule authenticationtype = NTLM
Smtpntlmauthenticationmodule authenticationtype = wdigest
Smtpntlmauthenticationmodule authenticationtype = Login
Run the smtpclient. Credentials. getcredential method four times to check whether this module is supported.
While smtpclient. Credentials is the icredentialsbyhost interface.
There are two icredentialsbyhost instances.
Credentialcache
Networkcredential
Networkcredential
Public networkcredential getcredential (string host, int port, string authenticationtype)
{
Return this;
}
All modules are supported (so use the first module smtpnegotiateauthenticationmodule ).
And credentialcache
Public networkcredential getcredential (string host, int port, string authenticationtype)
{
Networkcredential credential = NULL;
Idictionaryenumerator enumerator = This. cacheforhosts. getenumerator ();
While (enumerator. movenext ())
{
Credentialhostkey key = (credentialhostkey) enumerator. Key;
If (key. Match (host, port, authenticationtype ))
{
Credential = (networkcredential) enumerator. value;
}
}
Return credential;
}
Higher than authenticationtype
Conclusion
Therefore, if your pclient needs to change the authentication method, it should use credentialcache.
Credentialcache mycache = new credentialcache ();
Mycache. Add (hosttextbox. Text, 25, "login", new networkcredential (usernametextbox. Text, passwordtextbox. Text ));
Smtpclient. Credentials = mycache;
The third parameter cannot be used (the match fails when the parameter is set, and the certificate does not exist). There are the following four types (as can be seen from the module), regardless of the size of the parameter.
Gssapi
NTLM
Wdigest
Login
This is the same as the package content sent with outlook.