.NET 2.0 System.Net.CredentialCache

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
 
G

Guest

SmtpClient mailClient = new SmtpClient();
mailClient.Credentials = new NetworkCredential("userName", "password");
 
G

Guest

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.
 

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