?
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
?
348 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…
Suggested Courses

762 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