?
Solved

System.Web.MAIL -> TRY CATCH and send error message to a string to be appended to a log

Posted on 2004-08-04
4
Medium Priority
?
352 Views
Last Modified: 2006-11-17
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.

0
Comment
Question by:mjlthomas
  • 2
4 Comments
 

Author Comment

by:mjlthomas
ID: 11718515
General Code example as Follows:

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.Net\Exports\" & RPTName & "." & ExportType, MailEncoding.UUEncode)
                .Attachments.Add(myAttachment)
                .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.TimeOfDay & ": Message Relayed to Server:    " & RPTName & vbCrLf & "       Message Recipients: " & emails & vbCrLf & StatusBox.Text
            SendReportFlag = True
0
 
LVL 4

Accepted Solution

by:
jrandallsexton earned 150 total points
ID: 11719411
Try
...
Catch ex as smtp
Catch ex as exception
   Console.Writeline(ex.mesage & " : " & ex.innerexception.tostring)
End Try

----------------- This can't be what you want; would be way too easy.
0
 
LVL 1

Expert Comment

by:Vartana
ID: 11720425
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
0
 
LVL 4

Expert Comment

by:jrandallsexton
ID: 11720441
Remove my "Catch ex as smtp" --> that was supposed to have been cut out by me.  Whoops.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question