Sending Email from Progress - What if Outlook is Not Running

Posted by noblesw on 17-Dec-2009 08:12

I have been using the following code to open an Outlook (native window) email screen using the automation object.  It works great, as long as Outlook is already open.  If it isn't open, I can't seem to trap that condition.  The problem is that the "Recipients" method always raises an error condition if Outlook is not open, and I can't seem to test the validity of a com-handle in advance of using that method.

DEF VAR outlook AS COM-HANDLE.
DEF VAR chMailElement AS COM-HANDLE.
DEF VAR chMailRec as COM-HANDLE.
DEF VAR chNameSpace as COM-HANDLE.
DEF VAR chRecipients AS COM-HANDLE NO-UNDO.


CREATE "outlook.Application":U outlook.

chNameSpace = outlook:GetNameSpace("MAPI":u).

IF NOT VALID-HANDLE(chNameSpace)
   THEN MESSAGE "NameSpace issue."  VIEW-AS ALERT-BOX.

/* 0 = email, 1 = appointment, 2 = contact */
chMailElement = outlook:CreateItem(0).

IF NOT VALID-HANDLE(chMailElement)
   THEN MESSAGE "MailElement issue."  VIEW-AS ALERT-BOX.

chRecipients = chMailElement:Recipients.

IF NOT VALID-HANDLE(chRecipients)
   THEN MESSAGE "Recipients Issue."  VIEW-AS ALERT-BOX.
   ELSE chMailRec = chMailElement:Recipients:Add("send2you@url.com").
    
NO-RETURN-VALUE chMailElement:display.
RELEASE OBJECT outlook.

All Replies

This thread is closed