Welcome, Guest
Username: Password: Remember me
Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET
  • Page:
  • 1

TOPIC:

Using Outlook from VO 17 Jan 2021 17:43 #17204

  • Jan@share.be's Avatar
  • Topic Author


  • Posts: 48
  • 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

    Please Log in or Create an account to join the conversation.

    Using Outlook from VO 18 Jan 2021 13:10 #17209

    • ic2
    • ic2's Avatar


  • Posts: 1573
  • 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

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1