Announcement

Collapse
No announcement yet.

Does anyone know hot to open MS Outlook programmaticly and pass data in?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Does anyone know hot to open MS Outlook programmaticly and pass data in?

    Does anyone know hot to open MS Outlook programmaticly and pass data in? I am trying to start outlook and pass in the subject and body. OLE? Wondering where I should start my search...

  • #2
    You might need to look at Outlook Redemption for some of the stuff you want to do... either way a really good resource.
    <b>George W. Bleck</b>
    <img src='http://www.blecktech.com/myemail.gif'>

    Comment


    • #3
      Search for MAPI

      here is some code that works with outlook 2010, don't know if it works with newer versions.

      Code:
      #COMPILE EXE
      #DIM ALL
      
      #IF NOT %DEF(%TRUE)
      %TRUE   = 1
      #ENDIF
      #IF NOT %DEF(%FALSE)
      %FALSE  = 0
      #ENDIF
      #IF NOT %DEF(%NULL)
      %NULL   = 0
      #ENDIF
      
          %olFormatUnspecified = 0
          %olFormatPlain = 1
          %olFormatHTML = 2
          %olFormatRichText = 3
      
          %olMailItem = 0
      
          %olImportanceLow = 0
          %olImportanceNormal = 1
          %olImportanceHigh = 2
      
      
      %DisplaySend = -1       ' -1 Display, else Send
      
      FUNCTION PBMAIN () AS LONG
      LOCAL saMapiProf () AS STRING
      LOCAL lErrCode AS LONG
      LOCAL lResult AS LONG
      
       SendOutlookMail ("To@mail.com; other@mail.net", "cc@mail.net", "my subject", "body text", %olFormatPlain, %olImportanceNormal, %DisplaySend)
      
      END FUNCTION
      
      '=============================================================================
      ' SendOutlookMail() Function using late-binding and minimal error checking
      '=============================================================================
      FUNCTION SendOutlookMail( BYVAL sEmailTo     AS WSTRING, _
                                BYVAL sEmailCC     AS WSTRING, _
                                BYVAL sSubject     AS WSTRING, _
                                BYVAL sBodyText    AS WSTRING, _
                                BYVAL lBodyFormat  AS LONG,   _
                                BYVAL lImportance  AS LONG,   _
                                BYVAL lDisplayOnly AS LONG _
                                ) EXPORT AS LONG
      
         LOCAL oOutlook   AS DISPATCH
         LOCAL oMessage   AS DISPATCH
         LOCAL oRecipient AS DISPATCH
         LOCAL oAttach    AS DISPATCH
      
         LOCAL sName AS WSTRING
         LOCAL i     AS LONG
      
         LOCAL vVar  AS VARIANT
         LOCAL vTemp AS VARIANT
      
         '===========================
         ' Create an outlook session
         '
         oOutlook = NEWCOM "Outlook.Application"
         IF ISFALSE ISOBJECT(oOutlook) THEN
            ? "Outlook Object Could not be created", %MB_OK, "Error"
            FUNCTION = %FALSE
            EXIT FUNCTION
         END IF
      
      
         '================================
         ' Create a Message
         '
         LET vTemp = %olMailItem
         OBJECT CALL oOutlook.CreateItem(vTemp) TO oMessage
         IF ISNOTHING(oMessage) THEN ? "oMessage failed. err=" & STR$(ERR)
      
      
         '==================================
         ' Create Recipient
         '
            sName = sEmailTo
            LET vTemp = sName
            OBJECT LET oMessage.TO = vTemp
      
      
         ' Add a CC if specified
               sName = sEmailCC
               LET vTemp = sName
               OBJECT LET oMessage.CC = vTemp
      
         ' Add the email Subject
         LET vTemp = sSubject
         OBJECT LET oMessage.Subject = vTemp
      
      
         ' Add the email body based on the format
         LET vTemp = sBodyText
         SELECT CASE lBodyFormat
            CASE %olFormatUnspecified, %olFormatPlain
               OBJECT LET oMessage.Body = vTemp
            CASE %olFormatHTML
               OBJECT LET oMessage.HTMLBody = vTemp
            CASE %olFormatRichText
               OBJECT LET oMessage.RTFBody = vTemp
         END SELECT
      
      
         ' Set the email importance
         LET vTemp = lImportance
         OBJECT LET oMessage.Importance = vTemp
      
      
         '=======================================================================
         ' Display Message Before Sending
         '
         IF ISTRUE(lDisplayOnly) THEN
            OBJECT CALL oMessage.Display
         ELSE
            OBJECT CALL oMessage.Save
            OBJECT CALL oMessage.Send
            '? "Outlook Email has been sent.", %MB_OK, "Success"
         END IF
      
         SET oOutlook = NOTHING
         FUNCTION = %TRUE
      
      END FUNCTION

      Comment


      • #4
        Thanks everybody! Very helpful!

        Comment


        • #5
          Would someone please test if this code will attach a file using Outlook 2010 or Outlook?
          I read somewhere Microsoft products allow attach to work with Shell.
          Code:
          #INCLUDE "win32api.inc"
          FUNCTION PBMAIN () AS LONG 'ShellEmail.bas
           LOCAL zAttach AS ASCIIZ * 128
           LOCAL zText   AS ASCIIZ * 256
           zAttach = "test.txt"
           OPEN zAttach FOR OUTPUT AS #1
           PRINT #1, "A line of text"
           CLOSE #1
           IF ISFALSE(ISFILE(zAttach)) THEN
             ? zAttach + $CR + "Attachment file missing",%MB_SYSTEMMODAL,EXE.NAME$
             EXIT FUNCTION
           END IF
           zText = "mailto:" + "?"
           zText+= "&Subject=" + "Document attached"
           zText+= "&Body="    + "Please find the document attached"
           zText+= "&Attach="  + zAttach
           ShellExecute (%NULL, "OPEN", zText, BYVAL %NULL, CURDIR$, %SW_SHOWNORMAL)
          END FUNCTION
          https://www.tesla.com/roadster

          Comment


          • #6
            Originally posted by Mike Doty View Post
            Would someone please test if this code will attach a file using Outlook 2010 or Outlook?
            I read somewhere Microsoft products allow attach to work with Shell.
            Hi Mike,
            I have Outlook 2010 and everything worked except the attachment.
            I tried fully qualifying the attached file and with/without double quotes
            Googling it, the consensus was that attachments may have worked for older Office versions (2000?).
            An alternative, CDO, works well for me - but the flip side is that the sent email does not get stored in Sent Items - which may or may not suit your needs.
            Failing that, the MAPI interface would be the way to go. It's likely you know all this and are just looking for a simple Shellexecute solution. It would be handy.
            Regards, Ross

            Comment


            • #7
              I have a client with Windows 2010 and he wanted everything to go through Outlook.
              Forgot about the send folder, good grief, just finished a program to send without it
              Thank you!
              https://www.tesla.com/roadster

              Comment


              • #8
                Wound up doing it this way:
                Code:
                <a class="emailButton" href="mailto:?subject=This is the subject&body=This is the body. Please add card number 3865098 for Ken Cole.%0a%0aThanks!%0aDavid%0a">Email</a>

                Comment


                • #9
                  Is that a shellexecute command?
                  Code:
                  zText = "mailto:?subject=This is the subject&body=This is the body. Please add card number 3865098 for Ken Cole.%0a%0aThanks!%0aDavid%0a"
                  ShellExecute (%NULL, "OPEN", zText, BYVAL %NULL, CURDIR$, %SW_SHOWNORMAL
                  It might also be done by shellexecute "outlook.exe /paramenters" (if command line options were known)
                  https://www.tesla.com/roadster

                  Comment

                  Working...
                  X