mjlthomas
asked on
System.Web.MAIL -> TRY CATCH and send error message to a string to be appended to a log
Mostly I'm lazy today and don't want to think.
How do I trap exceptions from System.Web.MAIL.SmtpMail and put them in a string format.
How do I trap exceptions from System.Web.MAIL.SmtpMail and put them in a string format.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try
MyCode
Catch ex as System.Exception
'ex.ToString <---- this makes the exception to string then you can do whatever you want
msgbox( ex.ToString )
End Try
MyCode
Catch ex as System.Exception
'ex.ToString <---- this makes the exception to string then you can do whatever you want
msgbox( ex.ToString )
End Try
Remove my "Catch ex as smtp" --> that was supposed to have been cut out by me. Whoops.
ASKER
Dim myMail As New MailMessage
With myMail
.From = "some@where.com"
.To = emails & "; some@where.com"
.Subject = RPTName & " for " & dt
.Body = dt + " " + tm
Dim myAttachment As New MailAttachment("S:\Crystal
.Attachments.Add(myAttachm
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "A User Name") 'set your username here
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "A Password") 'set your password here
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", "240")
End With
SmtpMail.SmtpServer = "SERVERNAME"
SmtpMail.Send(myMail)
StatusBox.Text = Microsoft.VisualBasic.Time
SendReportFlag = True