sending mail via outlook ole - re-post

Emma

Member
Below is the original post. I added "NO-ERROR" to the send statement and again it runs outlook, but doesn't give me the previous error. i now get an outlook.exe error, then outlook proceeds to shut down, along with the the message.

Does anyone have any ideas about this?

Emma.
------------------------------------------------------------------------------
i am using the following code to send emails via outlook from progress. This works fine when outlook is already running. If it isn't, the code runs outlook, but doesn't send the email. If i click send i get this error:

Error occurred while accessing component property/method: SEND.
The server threw an exception.

Error code 0x80010105 sendmail d:\temp\p29814cf.ab (5890)


Does anyone have any ideas as to why this is happening, or how i can alter the code to send them without the errors happening?

Thanks.

Emma.

PROCEDURE sendmail:

DEFINE INPUT PARAMETER vAddress AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER vCCAddress AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER vBCCAddress AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER vSubject AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER vBody AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER vAttach AS CHARACTER NO-UNDO.

DEFINE VARIABLE hNameSpace AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hFolder AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hOutlook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hOutlookMsg AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hOutlookRecip AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hOutlookAttach AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE vShow AS LOGICAL NO-UNDO.
DEFINE VARIABLE X AS INTEGER NO-UNDO.
DEFINE VARIABLE w-i AS INTEGER INITIAL 1 NO-UNDO.

CREATE "Outlook.Application" hOutlook CONNECT NO-ERROR.

IF hOutlook = ? THEN
DO:
CREATE "Outlook.Application" hOutlook.
ASSIGN vShow = TRUE.
END.
ELSE
ASSIGN vShow = FALSE.

houtlookMsg = hOutlook:CreateItem(0).

DO X = 1 TO NUM-ENTRIES(vAddress):
hOutlookRecip = hOutlookMsg:Recipients:ADD(trim(substring(vAddress,w-i,
(index(vAddress,";")) - 1))).
ASSIGN vAddress = TRIM(SUBSTRING(vAddress,((index(vAddress,";")) + 1),
LENGTH(vAddress))).
hOutlookRecip:TYPE = 1.
END.

DO X = 1 TO NUM-ENTRIES(vCCAddress):
hOutlookRecip = hOutlookMsg:Recipients:ADD(trim(substring(vCCAddress,w-i,
(index(vCCAddress,";")) - 1))).
ASSIGN vCCAddress = TRIM(SUBSTRING(vCCAddress,((index(vCCAddress,";")) + 1),
LENGTH(vCCAddress))).
hOutlookRecip:TYPE = 2.
END.

DO X = 1 TO NUM-ENTRIES(vBCCAddress):
hOutlookRecip = hOutlookMsg:Recipients:ADD(trim(substring(vBCCAddress,w-i,
(index(vBCCAddress,";")) - 1))).
ASSIGN vBCCAddress = TRIM(SUBSTRING(vBCCAddress,((index(vBCCAddress,";")) + 1),
LENGTH(vBCCAddress))).
hOutlookRecip:TYPE = 3.
END.

DO X = 1 TO NUM-ENTRIES(vAttach):
hOutlookAttach = hOutlookMsg:Attachments:ADD(ENTRY(X, vAttach)).
END.

hOutlookMsg:Subject = vSubject.
hOutlookMsg:Body = vBody.
/* hOutlookRecip:Resolve. */
hNameSpace = hOutlook:GetNamespace("MAPI").
/* 3 deleted items, 4 outbox, 5 sent items, 6 inbox */
hFolder = hNameSpace:GetDefaultFolder(4).

IF vShow THEN
hFolderISPLAY.

hOutlookMsgISPLAY.

hOutlookMsg:SEND. /* sends the email message */


RELEASE OBJECT hOutlookAttach NO-ERROR.
RELEASE OBJECT hOutlookRecip NO-ERROR.
RELEASE OBJECT hOutlookMsg NO-ERROR.
RELEASE OBJECT hFolder NO-ERROR.
RELEASE OBJECT hNameSpace NO-ERROR.
RELEASE OBJECT hOutlook NO-ERROR.
END PROCEDURE.
 
Hi Emma,

I don't have time to debug your code at the minute so here is a sample code block which works with outlook. Perhaps you can modify it to fit your code... make sure that outlook is the standard email client though!

def var chSession as com-handle.
def var chMessage as com-handle.
def var chRecipient as com-handle.
def var chAttachment as com-handle.

create "MAPI.session" chSession.
chSession:logon.

chMessage = chSession:eek:utbox:messages:add.
chMessage:Subject = "To Mr Testman".
chMessage:Type = "IPM.Note".
chMessage:Text = "Hello Mr Testman".

/* Create one Recipient */
chRecipient = chMessage:Recipients:Add.
chRecipient:name = "Mr Testman".
chRecipient:Type = 1.
chRecipient:resolve.

/* Create one Attachment */
chAttachment = chMessage:Attachments:Add.
chAttachment:name = "test.txt".
chAttachment:Type = 1.
chAttachment:ReadFromFile("c:\test.txt").

/* Save and send message */
chMessage:Update.
chMessage:send(Yes, No, 0).

release object chAttachment.
release object chRecipient.
release object chMessage.
release object chSession.


hope this helps.
 
Top