Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


VB, ASP and sending email

Posted on 2001-06-05
Medium Priority
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
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

Expert Comment

ID: 6155994

Accepted Solution

dalexis earned 680 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 david_alexis@hotmail.com.

Good luck, and happy coding! :)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

636 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