Solved

VB, ASP and sending email

Posted on 2001-06-05
4
341 Views
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?
0
Comment
Question by:MLove
  • 2
4 Comments
 
LVL 4

Expert Comment

by:RichW
ID: 6155994
0
 
LVL 1

Accepted Solution

by:
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! :)
0
 

Author Comment

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

Expert Comment

by:dalexis
ID: 6159577
Sure.  Glad to be of any help.  My address is david_alexis@hotmail.com.

Good luck, and happy coding! :)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now