.NET 2.0 System.Net.CredentialCache

  • Thread starter Thread starter Tim Cowan
  • Start date Start date
T

Tim Cowan

Hi,

I am using .NET 2.0 and I want to send mail that uses SMTP authorization. I
have found this in the help:

client.Credentials = System.Net.CredentialCache.DefaultCredentials;

My question is how do I set the username and password? Say the username is
(e-mail address removed) and the password is onions, how do I set this? The values could
be different on a user by user basis, so I need to apply the settings from
the registry.

Thanks

Tim
 
SmtpClient mailClient = new SmtpClient();
mailClient.Credentials = new NetworkCredential("userName", "password");
 
And if you don't want to use the default credentials, you have to set the
property UseDefaultCredentials to false BEFORE assigning credentials to the
mailClient object! Dumb, but that's how the code works, as ai found out
while investigating an authentication problem I'm having with SmtpClient. If
you don't set UseDefaultCredentials to false beforehand, the assignment of
credentials is simply ignored.
 
Back
Top