VB, ASP and sending email

Posted on 2001-06-05
Last Modified: 2006-11-17
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?
Question by:MLove
  • 2

Expert Comment

ID: 6155994

Accepted Solution

dalexis earned 170 total points
ID: 6156657
(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! :)

Author Comment

ID: 6158643
I will go and do this, sounds very cool.  Would you mind if I email you with any problems?

Expert Comment

ID: 6159577
Sure.  Glad to be of any help.  My address is

Good luck, and happy coding! :)

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA filters 2 65
How to make an ADE file by code? 11 94
TT Auto Dashboard 13 95
VBA: copy range dynamically based on config sheet v2 3 48
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 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