If statement problem

  • Thread starter Thread starter karim
  • Start date Start date
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.
 
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
 
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.
 
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
 
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.
 
Back
Top