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
342 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now