Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

VB, ASP and sending email

I am working on a NT4 Server, with ActiveXDLL in VB, calling VB from ASP.  At a certain time at night our email server goes down, and then when members try to send an email from our site to our Inbox the following error occurs:
The information store could not be opened. [MAPI 1.0 - [MAPI_E_LOGON_FAILED(80040111)]]RCIJHB001

This never happened initially when we wrote this project, but after putting out a new exe one day, it started giving these errors.  I'm thinking of a work around or solution where when the emails are sent, they only get stored in the outbox or something, and as soon as the server comes up, they get sent.  Almost the same as when you use outlook express and press the send/receive button to send email.  

Any suggestions on this?
0
MLove
Asked:
MLove
  • 2
1 Solution
 
dalexisCommented:
(I appologize... this will be a bit long winded.)  :)

You can gain the kind of fault tollerance you want by creating an out-of-process (EXE) COM component that acts like a queue for the email. It needs to be out of process because you want it hanging around, retrying against the email server until it successfully sends all the queued emails.

The solution may seem a little inelegant, but such are the limitations of implementing this type of thing in VB.  (A C++ sulution would be more work, but would be much cleaner.)

The component needs to be follow the Singleton design pattern (Multiuse, single threaded).  Basically, the component will accepts requests from your ASP code to send emails.  It will add each request to a queue, which can be implemented using a Collection or array internally.  It will then asynchronously iterate thru the queued requests, attempting to send each email thru the email server.  If it encounters an error (as in when the server is down) it will wait for a period of time then attempt to send emails again.  Once the last email in the queue has been sent, the component kills itself.

That's the high level overview of what the component would do.  Let's drill into slightly more detail now...

COM would load the component when it is instantiated, but will destroy it when it goes out of scope in your ASP script.  This is not good, since the component may not have sent all emails successfully yet.  COM keeps an object loaded as long as there is at least 1 reference to it.  This is why you need the Form object.  All you need to do is Load the Form, and due to some quirkiness with the way VB handles Forms, COM thinks that the component still has a reference.  Therefore the component is not destroyed until the Form un Unloaded. :)

This said, when the first request comes in to your SendEmail method, simply Load the Form.  (Do NOT Show the form!  The component will be running as a background process on the server with no UI.) When the last email has been sent, Unload the Form.

Ok, now that we've fooled our component into hanging around after teh ASP script has finished with it, we need to set up the asynchronous mechanism to process the email requests in the background.  This is where our dummy Form comes in handy again.  Place a Timer control on the form.  This timer will be used to fire off a method to process the queued requests in the background.  The Timer's event handler will simply disable the timer, call the method to process the queue, then turn itself on again.  It should also check to see if all the queued requests have been sent.  If the queue is empty, it must disable the Timer and Unload the form.

Now that the Timer and the queue-processing event handler are in place, let's revisit the SendMail method.  It has a simple algorithm - Add the request details (to, from, subject, body, etc) to the queue object, Load the dummy Form (if it is not already loaded), and enable the Timer.  At this point, control returns to the your ASP script and life is good.

When the Timer interval has expired, the event handler fires and starts processing email requests in the background.

Once the basic functionality is working, you can add things like error logging, failsafe timeouts in case the server does not come back up within a given period of time, etc, etc.

Have fun! :)
0
 
MLoveAuthor Commented:
I will go and do this, sounds very cool.  Would you mind if I email you with any problems?
0
 
dalexisCommented:
Sure.  Glad to be of any help.  My address is david_alexis@hotmail.com.

Good luck, and happy coding! :)
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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now