Hope somebody with some experience in this field are willing to share some light on my problem.
Sending email is a crucial part of almost any web application today.
How would i go about monitoring the SMTP service running on the host machine 'better'?
Here is some background:
I used to make use of a remote server for sending mail to clients after subscription (notification emails) to our website.
Problem is that the server was down from time to time and thus not delivering any mail.
I had no way to monitor successfull mail deliveries.
Recently I started using the local SMTP mail service running on the host machine.
This seem to work better. Since IF the web server is running the mail server is also running as well.
But my problem is still the same.
I have no way of monitoring any successfull or unsuccessfull mail deliveries.
Ideally what i would like to have is:
The application testing each mail server (remote and local) before attempting to send any mail.
Then use server1 (if available) else
use server2 (if available) else
save email to db and notify systems admin
This seem like a failsafe way of going about the problem right?
Why am I asking this question?
Because i cant seem to find any good material on the local smtp service running on localhost.
There seem to be a lack of good tutorials of how the smtp service work and how to effectively interact with it using ASP.NET.
Can somebody please advise me on how to go about this?
Even a good tutorial or some book describing the advanced workings of the local SMTP service would greatly be appreciated.
Many thanks!!
I wrap thesend command in a try/catch block - if mail.send() is successful , then do next mail- if error, then log it etc..
don't know how to check if mail server is running...
HTH
Since your web server, and your mail server are operating on the same machine, I would look at a method of monitoring outside of your ASP.NET application, that writes to a log file you can monitor.
Using WMI you could monitor the status of the smtp service, and log it to a text file, then your web app could open that text file for reading before trying to send an email and scan it for a stop event of some sort. There may be a better way to do this, but with them both being on the same machine, this is probably the easiest.
Not sure if this is the best way. Just something I came up with real quick. I have not tested this, but should work fine. Place your appsettings in web.config for each SMTP server (i.e. SMTPSERVER0, SMTPSERVER1...etc). Basically this will try to send the email to SMTPSERVER0 and if it fails, it will increase to the next enum and recall the sub. Hope this helps!
PrivateSharedSub MailMessage(ByVal enum_ServerAs Smtp_Servers,ByVal strMessageAs String)
Dim mmAsNew MailMessage
mm.To = "somebody@.somewhere.com"
mm.From = "somebody@.somewhereelse.com"
mm.Subject = "Subject"
mm.BodyFormat = MailFormat.Text
mm.Body = strMessage
If enum_Server <> Smtp_Servers.LastEntryThen
SmtpMail.SmtpServer = ConfigurationSettings.AppSettings.Item("SMTPSERVER") & enum_Server
Try
SmtpMail.Send(mm)
Catch exAs Exception
MailMessage(enum_Server + 1, strMessage)
EndTry
Else
' No servers worked so write code to save email in db and notify sysadmins
EndIf
EndSub
PublicEnum Smtp_Servers
SMTP1 = 0
SMTP2 = 1
SMTP3 = 2
LastEntry = 3
EndEnum
0 comments:
Post a Comment