Using Outlook from VO

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
Post Reply
Jan@share.be
Posts: 64
Joined: Mon Nov 02, 2015 8:51 pm

Using Outlook from VO

Post by Jan@share.be »

Hi

Has anyone a good example of how to send an e-mail with Outlook from within a VO application.

Just want to create an email, set the recepient, subject and an attachment.
User has to press the sent button in outlook after verifying.

thanks
Jan
ic2
Posts: 1856
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Using Outlook from VO

Post by ic2 »

Hello Jan,

It's pretty old code, because as we have our own e-mail program, sending an e-mail to Outlook is no longer necessary in our programs, but this should basically do the trick:

Dick

FUNCTION SendMailOutlook(cSubject,cText,aFiles,aEmail) AS LOGIC

LOCAL cbOldErrorBlock AS CODEBLOCK
LOCAL oOutlook AS USUAL
LOCAL oMail AS USUAL
LOCAL oAttachment AS USUAL
LOCAL nTeller AS DWORD
LOCAL lRetVal AS LOGIC

lRetVal :=TRUE // Init some variables


IF lRetVal .AND. Empty(cSubject) // Check layout
END
IF lRetVal .AND. Empty(cText)
END

IF lRetVal
cbOldErrorBlock:=ErrorBlock() // Save previous error handler
BEGIN SEQUENCE
ErrorBlock({|X|DummyFunction(X)}) // Create new error handler
oOutlook:=OLEAutoObject{"Outlook.Application"} // Start Outlook
oMail:=oOutlook:CreateItem(0) // Create mail
RECOVER // Exception
lRetVal:=FALSE
END
ErrorBlock(cbOldErrorBlock) // Resore old error handler

IF lRetVal // All ok
FOR nTeller:=1 UPTO ALen(aEmail) // For sender objMail:add addresses to email
oMail:Recipients:Add(aEmail[nTeller])
NEXT nTeller

IF oMail:Recipients:ResolveAll() // Check if addresses are ok
oMail:Subject:=cSubject // Add subejct
oMail:Body:=cText // and body
oAttachment:=oMail:Attachments // and attachments:

FOR nTeller:=1 UPTO ALen(aFiles)
IF File(aFiles[nTeller])
oAttachment:Add(aFiles[nTeller])
END
NEXT nTeller
oMail:Send() // send
ELSE
WarningBox{NIL,Vt(MSG_EMAILMESSAGE,"Email message"),;
Vt(MSG_NOTALLEMAILADROK,"Not all email-adresses are correct")}:Show()
lRetVal:=FALSE
ENDIF
ELSE
WarningBox{NIL,Vt(MSG_EMAILMESSAGE,"Email message"),;
Vt(MSG_OUTLOOKNOTOK,"Outlook has not been installed properly!")}:Show()
lRetVal:=FALSE
ENDIF
END
RestoreDefaultPath("")
RETURN lRetVal
Post Reply