Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
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
?
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

647 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