471,603 Members | 1,559 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,603 software developers and data experts.

.NET 2.0 System.Net.CredentialCache

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
bo*@home.com 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
Jan 30 '06 #1
2 2528
SmtpClient mailClient = new SmtpClient();
mailClient.Credentials = new NetworkCredential("userName", "password");

"Tim Cowan" wrote:
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
bo*@home.com 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

Jan 30 '06 #2
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.

"CPrice79" wrote:
SmtpClient mailClient = new SmtpClient();
mailClient.Credentials = new NetworkCredential("userName", "password");

"Tim Cowan" wrote:
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
bo*@home.com 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

Feb 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.