If statement problem

K

karim

Hello All, I have this code:

Dim mail As New MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text,
txtBody.Text)
Dim client As New SmtpClient(txtSMTP.Text)
If client.Credentials = CredentialCache.DefaultNetworkCredentials Then
client.Send(mail)
MessageBox.Show("Message Sent", "Information")
Me.Close()
Else
MessageBox.Show("Please fill out all places")
End If

and I have the blue error line under the statement after "If". does anyone
see what I'm missing?

Thanks for all your help.
 
S

Scott M.

karim said:
Hello All, I have this code:

Dim mail As New MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text,
txtBody.Text)
Dim client As New SmtpClient(txtSMTP.Text)
If client.Credentials = CredentialCache.DefaultNetworkCredentials
Then
client.Send(mail)
MessageBox.Show("Message Sent", "Information")
Me.Close()
Else
MessageBox.Show("Please fill out all places")
End If

and I have the blue error line under the statement after "If". does anyone
see what I'm missing?

Thanks for all your help.

If you hover your mouse over the blue-wavy underline, you'll get more
specific information about the error, which we could use to help you out.

-Scott
 
M

Mike Williams

karim said:
Hello All, I have this code:

Dim mail As New MailMessage ' . . . (etc
Dim client As New SmtpClient(txtSMTP.Text)
If client.Credentials = CredentialCache.DefaultNetwork ' . . . (etc)
. . . and I have the blue error line under the statement after "If".
does anyone see what I'm missing?

You've probably pasted the code directly into your Form's declarations
section instead of into a Sub or Function.
 
F

Family Tree Mike

karim said:
Hello All, I have this code:

Dim mail As New MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text,
txtBody.Text)
Dim client As New SmtpClient(txtSMTP.Text)
If client.Credentials = CredentialCache.DefaultNetworkCredentials Then
client.Send(mail)
MessageBox.Show("Message Sent", "Information")
Me.Close()
Else
MessageBox.Show("Please fill out all places")
End If

and I have the blue error line under the statement after "If". does anyone
see what I'm missing?

Thanks for all your help.

I'm getting (VS 2008) an error on the comparison within the if statement.
Client.Credentials (ICredentialsByHost) are based on a particular server,
while CredentialCache.DefaultNetworkCredentials are network based
(NetworkCredential).

There is more about this in the remarks section of the MSDN docs for
SmtpClient.Credentials.

Mike
 
K

karim

I think you are right Mike. The message I am getting says (operator '=' is
not defined for types system.net.IcredentialsByHost and system. net.network
credential.
 

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

Similar Threads


Top