Visual Basic 6.0 email assistance requested please

Dear Expert,

The below code logs into our exchange server and successfully sends an email message. Using this same existing connection, is there something I can add so that it could loop thru all messages found on the strUser account and only count the ones in which the subject contains Alert?  Please help.

Set MyEmail = Nothing
Set MyEmail = CreateObject("CDO.Message")
MyEmail.Subject = "Subject"
MyEmail.TextBody = "Body"

MyEmail.Configuration.Fields.Item("") = 2
MyEmail.Configuration.Fields.Item("") = strDomain
MyEmail.Configuration.Fields.Item("") = 25
MyEmail.Configuration.Fields.Item("") = 2
MyEmail.Configuration.Fields.Item("") = strUser
MyEmail.Configuration.Fields.Item("") = strPassword
MyEmail.Configuration.Fields.Item("") = 100


Set MyEmail = Nothing
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robberbaron (robr)Commented:
yes but it only works for Exchange 2003 and earlier...  ExchangeOLEDB  & WebDAV.

i moved to C# for this reason, using Exchange Managed API/
could loop thru all messages found on the strUser account
So that suggests you want to POP the emails and process the emails. ASP might not be the best environment for building such an application. You actually need something that continues to run and monitor the strUser email account even when no users are browsing the ASP pages. In light of that, a Windows Service or a Command Line application scheduled in Windows Scheduler to run at intervals might be best.

To check emails, there are a few options, and they depend on what is supported by your server. Sometimes. you IT can enable the alternatives. For an Exchange Server, there is the Exchange Web Services/ActiveSync/Managed API. The other email protocols are POP and IMAP. Classic ASP (AFAIK) does not have a native componnent for any of these protocols. You can go third party and find ActiveX controls that can do this (AfterLogis MailBee, EasyMail POP3 ( wonderful example for EasyMail here), SoftArtisans, and so on). These are examples of libraries that will do this from Classic ASP.

That said... I would agree with RobberBaron. C# might be easier... This has become a lot easier now, in the .NET world. There are open source options, and commercial options available. It will also be easier to write a windows service in .NET. I have used MailBee.NET for processing POP/IMAP + SMTP emails and I am very happy with it. For connecting to Exchange, I tried Aspose Email (but I ditched it in favour of the Exchange Managed API)
Apples01Author Commented:
Thank you for the responses.  The strUser account is actually an account found on our exchange server (not a POP or IMAP  accont).  I tried connecting via IMAP using an Outlook profile stored on the pc and it does connect however it seems outlook needs to be running in order for the count to be a true real-time accurate count. Also this VB app is always running as service.  I am not sure how I would start and close outlook nicely so things do not get corrupted.  Please help.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

The strUser account is actually an account found on our exchange server (not a POP or IMAP  accont).
Exchange can be configured to allow POP for example and you would be able to access the same account via POP.

IF you use the components I proposed earlier, then you don't need outlook because they are actually email clients themselves. Only without the GUI like Outlook does.

IF you want to rely on outlook, you can write an add-in which will get notified whenever outlook receives new mail. You could then do you prices in these events.,
Apples01Author Commented:
IF you want to rely on outlook, you can write an add-in which will get notified whenever outlook receives new mail.

Yes, I would to rely on outlook and the exchange account that it has.

I'm sorry but doesn't outlook need to be started first in order for this add-in option to have current information?
Yes. Outlook would need to be open in order for that option to work.

For a Windows service scenario... Where you don't need outlook and the email checking happens even when no user is logged on then you need the exchange managed api or aspose.
Apples01Author Commented:
Thank you. I will have to speak with our network administrator in regards to  exchange managed api or aspose.   In the meantime, does anyone know how to open and close outlook 2007 nicely using Visual Basic?
How to automate Outlook by using Visual Basic

That shows guidance from Microsoft how to do this right.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.