Outlook gives "operation failed" error

Dear All,

I am using OUTLOOK 2003 SP3 objects to send an email through Progress.

After I send the email and I try to open outlook I get an error message stating "operation failed" and outlook does not open. When I check the task manager - processes, I see outlook.exe in that and when I end that process and try to open outlook it works fine.

What can be wrong with my code? I am releasing all the COM-HANDLES after I send the mail. Is this because of memory leakage?

Could someone help me?

Thanks
Joel
 

Cringer

ProgressTalk.com Moderator
Staff member
An example of your code might be helpful. It would certainly igve better context for what you're asking.
 
An example of your code might be helpful. It would certainly igve better context for what you're asking.

Thanks Cringer. The following is the code.

define input parameter ic-email-ids AS CHARACTER no-undo. /* format - "abc@abc.com,1;bbc@bbc.com,2;cbc@cnn.com,3" - 1 stands for TO, 2 for CC */
define input parameter ic-subject AS CHARACTER no-undo.
define input parameter ic-body AS CHAR no-undo.
define input parameter ic-attachments AS CHAR no-undo.
DEFINE input parameter il-MailWindowVisible AS logical NO-UNDO.
{ mast\msgdef.i "olmail" } /* lanv */
DEFINE VARIABLE objOutlook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE objOutlookMsg AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE objOutlookRecip AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE l-ErrorsEncountered AS logical NO-UNDO.
define variable choice as logical initial true no-undo.
if il-MailWindowVisible then
do:
repeat:
CREATE "Outlook.Application" objOutlook connect no-error. /* outlook should be already be open for this case to work */
if ERROR-STATUS:ERROR then
do:
MESSAGE "Please open Outlook mail and then click on 'OK' to continue or click 'Cancel' to abort the mailing process."
VIEW-AS ALERT-BOX QUESTION BUTTONS OK-CANCEL
TITLE "Outlook must be open"
UPDATE choice.
if not choice then
return error.
end.
else
leave.
end.
end.
else do:
CREATE "Outlook.Application" objOutlook NO-ERROR.
if ERROR-STATUS:ERROR then
do:
l-help-msg-x = "The automation server for 'Outlook.Application' is not registered properly.|" +
"Please reinstall this server or try registering it again".
ASSIGN /* land */
{mast\msgprog-assign.i}
msg-mes-code = '29'
msg-mes-title = "Automation Server Error"
msg-mes-line = l-help-msg-x
msg-mes-type = "I"
msg-control = "DIA"
msg-readd-record = "1"
.
{ mast\msgctr.cal }
return.
end.
end.
run SetMailAttributes.
if not il-MailWindowVisible then
do:
if l-ErrorsEncountered then
do:
l-help-msg-x = "Errors displayed previously prevent sending this email.".
ASSIGN /* land */
{mast\msgprog-assign.i}
msg-mes-code = '49'
msg-mes-title = "Send Failed"
msg-mes-line = l-help-msg-x
msg-mes-type = "I"
msg-control = "DIA"
msg-readd-record = "1"
.
{ mast\msgctr.cal }
if valid-handle(objoutlookMsg) then
objoutlookMsg:delete.
end.
else
objOutlookMsg:Send.
end.
RELEASE OBJECT objOutlookMsg.
RELEASE OBJECT objOutlookRecip.
RELEASE OBJECT objOutlook.

PROCEDURE add-mail-id:
define input parameter mail-id AS character no-undo.
define input parameter type-to-cc-bcc AS INTEGER no-undo. /* to - 1, cc - 2, bcc - 33*/
objOutlookRecip = objOutlookMsg:Recipients:Add(mail-id).
objOutlookRecip:Type = type-to-cc-bcc.
objOutlookRecip:Resolve.
if not objOutlookRecip:Resolved then
do:
l-help-msg-x = "Unable to resolve email-id emailid.".
ASSIGN /* land */
{mast\msgprog-assign.i}
msg-mes-code = '62'
msg-mes-title = "Email-ID Error"
msg-mes-line = l-help-msg-x
msg-mes-type = "I"
msg-var-names = "emailid"
msg-var-values = mail-id
msg-control = "DIA"
msg-readd-record = "1"
.
{ mast\msgctr.cal }
l-ErrorsEncountered = true.
end.
END.
procedure ATTACH:
define input parameter fname AS CHARACTER no-undo.
DEFINE VARIABLE objOutlookAttach AS COM-HANDLE NO-UNDO.

objOutlookAttach = objOutlookMsg:Attachments:Add(fname) no-error.
if not valid-handle(objOutlookAttach) then
do:
l-help-msg-x = "Error attaching file '"+ fname + "'".
ASSIGN /* land */
{mast\msgprog-assign.i}
msg-mes-code = '83'
msg-mes-title = "Error Attaching"
msg-mes-line = l-help-msg-x
msg-mes-type = "I"
msg-control = "DIA"
msg-readd-record = "1"
.
{ mast\msgctr.cal }
l-ErrorsEncountered = true.
end.
END PROCEDURE.

PROCEDURE SetMailAttributes:
DEFINE VARIABLE counter AS INTEGER NO-UNDO.
DEFINE VARIABLE vc-email-id AS CHARACTER NO-UNDO.
DEFINE VARIABLE vc-email-where AS CHARACTER NO-UNDO.
DEFINE VARIABLE vc-attach AS CHARACTER NO-UNDO.
objoutlookMsg = objOutlook:CreateItem(0).
if il-MailWindowVisible then
objoutlookMsg:display().
DO counter = 1 TO NUM-ENTRIES(ic-email-ids,";"):
ASSIGN
vc-email-id = ENTRY(counter,ic-email-ids,";")
vc-email-where = "1".
IF NUM-ENTRIES(vc-email-id) > 1 THEN DO:
vc-email-where = ENTRY(2,vc-email-id).
IF LOOKUP(vc-email-where,"1,2,3") EQ 0 THEN
vc-email-where = "1".
END.
run add-mail-id(vc-email-id,integer(vc-email-where)).
END.
objOutlookMsg:Subject = ic-subject.
objOutlookMsg:Body = ic-body.
DO counter = 1 TO NUM-ENTRIES(ic-attachments):
vc-attach = ENTRY(counter,ic-attachments).
run ATTACH(vc-attach).
END.
END PROCEDURE.
 
Top