I'm trying to set up a procedure in my program that will send me an email if the program encounters an error.
I found the code online, but can't get it to work. I went to microsoft's site, but what appeared to be the relevant section, did not have vb.net examples, just c#, which I am less than efficient in.
I have these things set up at the begining of my program:
But when i run the code I get an "SMTPException Occurred. Failure sending mail"
This is the call i'm making to the procedure:
", "firstname.lastname@example.org", "Test Email", "This is a test!", True)
Any ideas where i might be going astray?
Thanks for your help!!!
Sub SendMail(ByVal StrMailfrom As String, ByVal StrMailTo As String, ByVal StrMailSubj As String, ByVal StrMailBody As String, ByVal FlagMailformat As Boolean)
'Obtain the Network Credentials from the mailSettings section
Dim credential As New System.Net.NetworkCredential("email@example.com", "mypassword")
'Create the SMTP Client
Dim client As New SmtpClient()
client.Host = "mail.myserver.com"
client.DeliveryMethod = SmtpDeliveryMethod.Network
'client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
client.Credentials = credential
client.Port = 366
'Build Email Message
Dim email As New MailMessage
email.From = New MailAddress(StrMailfrom)
email.Subject = StrMailSubj
email.IsBodyHtml = True
email.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
email.Body = StrMailBody
email.Sender = New MailAddress(StrMailfrom)
Catch e As Exception