Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an Email Arrived Pop-up

Status
Not open for further replies.

tacs

Programmer
Nov 21, 2005
46
GB
I'm new to this forum so I hope you can help.

I have an app that creates emails from within itself and puts them into Outlooks outbox. My user is now asking if I can create a pop-up when and email on a specific subject arrives and I'm not too sure where to start. I've now got a means of opening up outlook and finding the relevant unread emails from a prg, but my uncertainty surrounds the pop-up part.

I'm thinking that I need to create an app that sits in the system tray and monitors outlook periodically. Am I on the right track and would this be a COM server? Never created COM objects so I'm not sure where to begin.

Thanks
David
 
Thanks VERY much. How quick was that response?!

I'll give it a whirl now.

David
 
Hi again

Sorry, but I'm obviously missing something, as I said I haven't played with COM servers before.

I have installed VFPCOM which has stopped an error message when I try to run the program.
I created a prg in a new project with a single prg file which now looks like this :

#DEFINE olFolderCalendar 9
#DEFINE olFolderContacts 10
#DEFINE olFolderDeletedItems 3
#DEFINE olFolderInBox 6
#DEFINE olFolderJournal 11
#DEFINE olFolderNotes 12
#DEFINE olFolderOutBox 4
#DEFINE olFolderSentMail 5
#DEFINE olFolderTask 13
#DEFINE olBusy 2
#DEFINE True .T.
#DEFINE False .F.
#DEFINE olPrivate 2
#DEFINE MAILITEM 0
#DEFINE IMPORTANCELOW 0
#DEFINE IMPORTANCENORMAL 1
#DEFINE IMPORTANCEHIGH 2

#DEFINE VFPCOM_CLSID 'VFPCOM.COMUTIL'
#DEFINE OUTLOOK_CLSID 'OUTLOOK.APPLICATION'

public goVFPCOM, goOutlook, goLink
goVFPCOM = create(VFPCOM_CLSID)
goOutlook = create(OUTLOOK_CLSID)
goLink = create('OutlookApplicationEvents')
goVFPCOM.BindEvents(goOutlook, goLink)
DEFINE CLASS OutlookApplicationEvents AS custom OLEPUBLIC
PROCEDURE ItemSend(Item,Cancel)
ENDPROC
PROCEDURE NewMail
MessageBox('New Mail Has Arrived')
ENDPROC
PROCEDURE OptionsPagesAdd(Pages)
ENDPROC
PROCEDURE Quit
ENDPROC
PROCEDURE Reminder(Item)
ENDPROC
PROCEDURE Startup
ENDPROC
ENDDEFINE

I build the project as a COM server and run it. The screen flashes up a white window which disappears right away, but nothing appears in the tray area and when I send myself a new email nothing happens.

I've been looking at the help files in VFP8 which tells I needed to make the DEFINE CLASS as OLEPUBLIC (which I have done). Also tried it with /regserver, but nothing seems to happen.

Can you tell me what I am missing? Thanks.
David
 
but nothing appears in the tray area and when I send myself a new email nothing happens.

In the tray area? What did you want to appear there? To solution is only an example, but it is meant to run within an application, and a "wait window" is meant to pop-up but nothing else.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Like I said, I'm new to this so I don't know what to expect.

If I had seen a wait window I would have understood, but I don't see anything anywhere, not in the tray, not on the status bar, not as a wait window. As I said, I'm not questioning the example code, just what I am doing with it.

Thanks anyway.
David
 
This sounds like something you'll want to build as an add-in for Outlook, not a VFP app (unless you only want this to happen when your application is running). I've built add-ins for the other Office apps, but not for Outlook, so can't provide too much guidance, except the name.

Tamar
 
First of all, thanks to everyone.

I have added the code to my original app. By adding a new screen that I can minimise within the app itself and getting the code to run from a timer event it does the job. It means I can call the new routine to check for mail at pre-defined time intervals from a minimised form and then maximise the window if new and unread mail is found which will do nicely.

Thanks again.
 
Hello Tacs.

I have an app that creates emails from within itself and puts them into Outlooks outbox. My user is now asking if I can create a pop-up when and email on a specific subject arrives and I'm not too sure where to start.

You do not say which version of VFP you are using, but if you are using version 7 or later, you do not need a timer. You can do this using by creating a VFP handler object that implements the correct interface in Outlook and associate the handler with your outlook object using the EVENTHANDLER() function. Here is a sample Outlook Handler Class definition (save it as OutlookHandler.prg on your computer) Note that this is using Outlook XP so the version number is 9.1 - if you are using a different version, you must use the correct version number ( I am guessing that it is 9.0 for 2K and 9.2 for 2003 - the easiest way to check this is to register the Outlook type library using the IntelliSense manager and then look at the record in the FoxCode table ):

Code:
DEFINE CLASS OutLookHandler AS SESSION OLEPUBLIC

  IMPLEMENTS ApplicationEvents IN {00062FFF-0000-0000-C000-000000000046}#9.1
  *!*    IMPLEMENTS ApplicationEvents IN "d:\officexp\office10\msoutl.olb"

  PROCEDURE ApplicationEvents_ItemSend(ITEM AS VARIANT, CANCEL AS LOGICAL) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents_NewMail() AS VOID
  ? [New mail has arrived!]
  ENDPROC

  PROCEDURE ApplicationEvents_Reminder(ITEM AS VARIANT) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents_OptionsPagesAdd(PAGES AS VARIANT) AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents_Startup() AS VOID
  * add user code here
  ENDPROC

  PROCEDURE ApplicationEvents_Quit() AS VOID
  * add user code here
  ENDPROC

ENDDEFINE

And here is how you would use it - try this in the command window and then send yourself an e-mail in Outlook. You will see "New mail has arrived!" printed on the VFP desktop when the e-mail arrives in your in box.

Code:
oOutlook = CREATEOBJECT( [Outlook.Application] )
oHandler=NEWOBJECT( [OutlookHandler], [OutlookHandler.prg] )
EVENTHANDLER( oOutlook, oHandler )

You can modify the handler's ApplicationEvents_NewMail() method to do whatever you need it to do when new mail arrives.


Marcia G. Akins
 
Hi Marcia

Thanks very much for this.

I'm using VFP8. As I'm sure you will know, all was going smoothly until I started to test on Outlook 2003 instead of Outlook 2000 that didn't have the security patch installed. I then started getting the security messages which will drive my users nuts. My app send out a scheduled set of reports via email over night and so is unmanned. Thanks to mgannon's posts and FAQs I have already sorted this part out using CDO which seems to be great.

Having just run the test you suggested I get the results you also said I would get. As I'm not going to know which version of outlook the users have, is there away to find out from within the app?

Thaks again for all your help
David
 
As I'm not going to know which version of outlook the users have, is there away to find out from within the app?

Probably. I tried this in the command window with Outlook XP:

Code:
o=CREATEOBJECT([outlook.application])
?o.Version

and it came back with 10.0.0.4608. So I suppose you could try this with Outllok 2k and 2003 and see what versions they come back with.



Marcia G. Akins
 
Thanks Marcia, I'll give that a whirl now.

The security patches seem to have taken the fun out of this completely! I was just getting to a point where i could get the app to look at and then list in a nice grid the unread emails matching a specific subject, but now ....

There seem to be many articles about sending email, but not many at all about reading email. Is there a CDO equivalent to help with this? I saw on one thread that someone was saying they had read the CDO.CHM, but I can't see this anywhere to see if it would help.

I would need the users to enter their server details, just as they would in Outlook pluse user name and password, but can it be done where they collect emails directly through VFP?
 
Hi Again

For reference:
Outlook 2003 comes back with 11.0.0.5608
Outlook 2000 comes back with 9.0.0.2711

David

 
Hi David.

There seem to be many articles about sending email, but not many at all about reading email. Is there a CDO equivalent to help with this?

The short answer is "I don't know". The only thing I have ever used CDO for is to send e-mail.

There are easy enough ways to get around the Draconian security patch from H*ll. Here are 2:







Marcia G. Akins
 
Thanks for your time Marcia.

I'll check them out. If I find anything else I'll post it to let you know. I've seen some messages about using Winsock to open up POP3, but can't see how it works yet.

David
 
As promised, here is the result of my testing.

ClickYes works absolutely fine. It's small and can be turned on and off within the application so it's just about a perfect answer to what I wanted to achieve.

Thanks again for all your help to everyone that contributed to this thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top