Emailed error reports

  • Thread starter Thread starter PokerMan
  • Start date Start date
P

PokerMan

Hi guys

I don't want to put email code in my app itself for security reasons as i
don't want a password in my code client side.

My app runs with a website in any case so i'd like to do this and this is my
requirement:

1) On any error catch error message
2) Send error message to my webpage
3) Have webpage create the body of email as the error msg, hide this jargon
from user, and have a simple "An error occured, please click send to let us
know blah blah"

Alternatively i was thinking i could just create a table in my database to
sote information on any errors that come through from a client. But i don't
want extra traffic through my server and db access on errors. Also the error
may cause a disconnection from my server and i know their internet is likely
to still be running so the website can be loaded.

So my question is, how do i go about posting that data message to my site in
order to put it in an email to be sent?

Thanks
 
Hi,

Why do you need a password to send an email?
If you have a client that should post an error message to a website and you need to use a username/password to log on to an smtp account, you can store the username and password in web.config and encrypt the section.

Read this article on a how to encrypt sections in web.config or app.config

http://msdn2.microsoft.com/en-us/library/53tyfkaw.aspx
 
Hello PokerMan,

I recommend to look at log4net, MS Exceptions Blocks, coz they have the functional
u are required

P> Hi guys
P>
P> I don't want to put email code in my app itself for security reasons
P> as i don't want a password in my code client side.
P>
P> My app runs with a website in any case so i'd like to do this and
P> this is my requirement:
P>
P> 1) On any error catch error message
P> 2) Send error message to my webpage
P> 3) Have webpage create the body of email as the error msg, hide this
P> jargon
P> from user, and have a simple "An error occured, please click send to
P> let us
P> know blah blah"
P> Alternatively i was thinking i could just create a table in my
P> database to sote information on any errors that come through from a
P> client. But i don't want extra traffic through my server and db
P> access on errors. Also the error may cause a disconnection from my
P> server and i know their internet is likely to still be running so the
P> website can be loaded.
P>
P> So my question is, how do i go about posting that data message to my
P> site in order to put it in an email to be sent?
P>
P> Thanks
P>
---
WBR, Michael Nemtsev [C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
Morten,

I dont want anything client side, encrypted or not. The only encryption i
trust is SSL over the wire. So as good an idea as it sounds it would only be
viable for me in a worst case scenario.

Michael,

Thanks i will look into that.

All this aside tho can we pretend i didnt mention what i want to do with it.
How do i send data to a website page to be placed in a web form?
 
Here is how I did it. Sorry it's in VB. Watch the way I used the
MailMessage and SmtpServer classes. Notice that you don't need a password
to plop a message onto an SMTP Server. Your web site or program runs "as" a
certain identity, for example, IUSR_COMPUTERNAME or ASPNET or whatever, so
the SMTP Server in this snippet will see that user account as the sender of
the message. In this example, I have used ADO.NET to fetch a list of
recipients from a table in the data warehouse.

Another interesting whammy was that at this place, they used McAfee
Antivirus, which blocked TCP 53 Out. So my StandardSampleFileInfo class
(referenced by my _fi variable) had to have methods in it to temporarily
stop, and then restart the McAfee services. So if you use McAfee in your
environment, you'll be interested in how to do that.

Public Sub NotifySampleLoad()

Dim cnstr As String = _
ConfigurationSettings.AppSettings("connectionString")

Dim cn As New SqlConnection(cnstr)
Dim cm As New SqlCommand("dbo.GetSurveyAdministrators", cn)
Dim da As New SqlDataAdapter(cm)
Dim dt As New DataTable()
Dim subject As String = "Sample Load Notification"

Dim path As String = _
AppDomain.CurrentDomain.BaseDirectory() & "LSFNotification.html"

Dim from As String = _
ConfigurationSettings.AppSettings("mailAccount")

Dim mail As MailMessage
Dim body As String
Dim sr As StreamReader = File.OpenText(path)
Dim message As String = sr.ReadToEnd()
sr.Close()

With cm
.CommandType = CommandType.StoredProcedure
.CommandTimeout = _

Convert.ToInt32(ConfigurationSettings.AppSettings("commandTimeout"))
.Parameters.Add("@productType", _fi.ProductType)
End With

Try
da.Fill(dt)
Catch exc As SqlException
Console.WriteLine(exc.Message)
End Try

SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("smtpServer")

_fi.stopMcAfee()

For Each dr As DataRow In dt.Rows
body = message
body = body.Replace("_DATE_", Date.Now.ToLongDateString())
body = body.Replace("_FIRSTNAME_", dr(1).ToString())
body = body.Replace("_LASTNAME_", dr(2).ToString())
body = body.Replace("_DESCRIPTION_", dr(4).ToString())
body = body.Replace("_SURVEYNAME_", dr(0).ToString())
body = body.Replace("_FILENAME_", _fi.PathFilename)
body = body.Replace("_LINECOUNT_", _fi.FileRecordCount.ToString())
body = body.Replace("_SSKEY_", _fi.SampleSourceKey.ToString())
body = body.Replace("_CLCOUNTS_", _fi.CompanyLocationCounts.ToHtml())
body = body.Replace("_PCOUNTS_", _fi.ProductCounts.ToHtml())
body = body.Replace("_ALERTS_", _fi.Alerts.Replace(vbCrLf, "<br>"))

mail = New MailMessage()

With mail
.Body = body
.BodyFormat = MailFormat.Html
.From = from
.Subject = subject
.To = dr(3).ToString()
End With

Try
SmtpMail.Send(mail)

Catch exc As Exception
Console.WriteLine(exc.Message)
Console.WriteLine(exc.InnerException.Message)
Console.WriteLine(exc.InnerException.InnerException.Message)
End Try
Next
_fi.startMcAfee()

End Sub

Public Sub stopMcAfee()

Dim proc As Process

proc = Process.Start("NET.EXE", "STOP McAfeeFramework")
proc.WaitForExit()

proc = Process.Start("NET.EXE", "STOP McShield")
proc.WaitForExit()

proc = Process.Start("NET.EXE", "STOP McTaskManager")
proc.WaitForExit()

End Sub

Public Sub startMcAfee()

Dim proc As Process

proc = Process.Start("NET.EXE", "START McAfeeFramework")
proc.WaitForExit()

proc = Process.Start("NET.EXE", "START McShield")
proc.WaitForExit()

proc = Process.Start("NET.EXE", "START McTaskManager")
proc.WaitForExit()

End Sub

--

Peace & happy computing,

Mike Labosh, MCSD MCT
Owner, vbSensei.Com

"Escriba coda ergo sum." -- vbSensei
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Email Bounce Error 3
How to Migrate IMAP Email to Office 365 Easily 0
Unsolicited Emails 12
My own email & website 0
Thunderbird problem 2
Outlook Outlook Error 0x80042110 0
Windows 10 How can I fix my corrupt registries? 1
Outlook Stops Downloading emails 5

Back
Top