I have a application that is using OPC UA SDK and I am trying to introduce a function that will send a email using the SMTP client.
the syntax for email send is;
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("***", "***")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "***"
Smtp_Server.Timeout = 10000
e_mail = New MailMessage()
e_mail.From = New MailAddress("***")
e_mail.To.Add("***")
e_mail.Subject = "Email Sending"
e_mail.IsBodyHtml = False
e_mail.Body = "Message Body"
Smtp_Server.Send(e_mail)
MsgBox("Mail Sent")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
I am also have the line Imports System.Net.Mail
The code that sends the email works okay in a test application but when I try and do the same code in the OPC application, I get a error and the inner exception details is below.
Message = "Unable to cast object of type 'System.Net.Mail.SmtpClient' to type 'System.Net.HttpWebRequest'."
Source = "OpcLabs.EasyOpcUA"
StackTrace = " at OpcLabs.EasyOpc.UA.Toolkit.ClientServer.UAClientEngineBase.VerifyServerCertificate(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)" & vbCrLf & " at System.Net.ServerCertValidationCallback.Callback(Objec...
TargetSite = {Boolean VerifyServerCertificate(System.Object, System.Security.Cryptography.X509Certificates.X509Certificate, System.Security.Cryptography.X509Certificates.X509Chain, System.Net.Security.SslPolicyErrors)}
Can you advise if I am doing something wrong or how to send a email when also using OPC UA SDK ?
Thanks
Neil