Operator '==' cannot be applied to operands of type 'void' and 'bool'

Hi experts,

just trying to turn this smtp.Send(msg); into a boolean condition

            if (smtp.Send(msg) ==false)===========this line errors
            Console.WriteLine(" Successfull");

how do i proceed
Who is Participating?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the error message means that the method Send does have a void return type, and not boolean.
you CANNOT do that.
you need to check if the object smtp has another property, that indicates if the Send was submitted sucessfully or not, or if there is an error message.
SirReadAlotAuthor Commented:
ok. back to this.

smtp has no other property to state if items is delivered or not. but i  found this  class SmtpFailedRecipientsException which throws an exception if nothing was thrown
SirReadAlotAuthor Commented:
hi angel,

i think i fixed the problem by using this  smtp.SendAsync(mail, null);.

         SendAsync==Sends the specified e-mail message to an SMTP server for delivery. This method does not block the calling thread and allows the caller to pass an object to the method that is invoked when the operation completes.

however is it wrong to use null

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.