Outlook OLE

610 views
Skip to first unread message

Nenad Batocanin

unread,
Jan 3, 2021, 9:12:03 AM1/3/21
to harbou...@googlegroups.com

First, happy new year everyone :)

 

Does anyone use OLE to send email via Outlook? It worked (until some Win update, probably), and then it stopped. I use command:

 

oOL := win_oleCreateObject( "Outlook.Application")

 

but this function now always returns NIL. You probably also know that MAPI is getting worse and worse and will soon be completely removed.

 

Regards, NB

 

Mel Smith

unread,
Jan 3, 2021, 3:33:18 PM1/3/21
to Harbour Users
Hi Nenad:
   Enrico Maria Giordano (from xHarbour) has an iteresting method of sending emails using the CDO methods (i.e. Collective Data Object) and using these methods to send emails from a GMAIL root.

   I adapted this successful method and have now got a reasonable way to send batch emails to my fellow residents in my senior park in Arizona.

   I'm showing part of my work below (very quickly edited) , but I have now generalized my 'sender' to have arrays of recipients, and arrays of attachments.

   Maybe this gives you an alternative way of sending batch emails.

-Mel

***** here below is the rudimentary SEND  test  proggie**** 
FUNCTION MAIN()

    LOCAL cFrom     := "from...@gmail.com"
    LOCAL cServer   := "smtp.gmail.com"
    LOCAL cTo       := "toa...@someplace.xxx"
    LOCAL aTo
    LOCAL aAttach
    LOCAL cSubject  := "A TEST EMAIL"
    LOCAL cMessage  := "This is Test Email from fromaddr to toaddr"
    LOCAL cUser     := "from...@gmail.com"
    LOCAL cPassword := "12345678"
    LOCAL cPort     := "465"
    LOCAL lSSL      := .T.
    LOCAL lNotification := .F.
    LOCAL lOK
    LOCAL lHtml
    lHtml := .F.

    aTo := ARRAY(2)
    aTo[1] := "jo...@someplace.net"
    aTo[2] :=  "fre...@faraway.org"

    aAttach := {}

    cMessage := "This is a Test Message body"

    lOK := SENDMAIL( cFrom, cServer, aTo, cSubject, cMessage, , , cUser, cPassword, ,lHtml , cPort, lNotification, lSSL )

    IF .NOT. lOK
      Alert("Failed to Send Email to "+cUser)
    ENDIF

    RETURN NIL


#command IF <condition> THEN <*statements*> => if <condition> ; <statements> ; end
#command DEFAULT <var> := <xpr> => if <var> = NIL ; <var> := <xpr> ; end


/* TRY / CATCH / FINALLY / END */
#xcommand TRY  => BEGIN SEQUENCE WITH {|oErr| Break( oErr )}
#xcommand CATCH [<!oErr!>] => RECOVER [USING <oErr>] <-oErr->
#xcommand FINALLY => ALWAYS


STATIC FUNCTION SENDMAIL( cFrom, cServer, aTo, cSubject, cMessage, aAttach, cSender, cUser, cPassword, aCc, lHtml, cPort, lNotification, lSSL )

    LOCAL lOk := .F.

    LOCAL oCfg, oMsg

    LOCAL cCc := ""
    LOCAL cFilNam := ""
    LOCAL i
    LOCAL lGotErr := .F.
    LOCAL nStep  // showing what 'step we are doing at the time of crash
    LOCAL lTryInit := .F.
    LOCAL nNextTo // pointer to Next cTo
    LOCAL nLenaTo
    DEFAULT lHtml         := "<html" $ LOWER( cMessage )
    DEFAULT lNotification := .F.
    DEFAULT lSSL          := .F.

    nLenaTo:= LEN(aTO)  // get number of recipients

    TRY
      FOR nNextTo = 1 to nLenaTo

         nStep := 0
         cTo:= aTo[nNextTo]
         IF valtype(cTo) <> "C"
            LOOP
         ENDIF
         cTo := alltrim(cTo)

         IF .NOT. lTryInit

           nstep++   // doing step 1
           oCfg = CREATEOBJECT( "CDO.Configuration" )
           lGotErr := .F.
           nstep++  // Doing step 2
           oCfg:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value = cServer
           lGotErr := .F.
           nstep++  // Doing Step3
           IF !EMPTY( cPort )
               oCfg:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := VAL( cPort )
           ENDIF
           nstep++  // Doing step 4
           oCfg:Fields( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value = 2
           nstep++  // Doing step 5
           oCfg:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value = .F.
           nstep++  // Doing step 6
           IF !EMPTY( cUser ) .AND. !EMPTY( cPassword )
             oCfg:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value = .T.
             oCfg:Fields( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value = cUser
             oCfg:Fields( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value = cPassword  // change assignment statement from := to =
             oCfg:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value = lSSL
           ENDIF
           nstep++  // Doing step 7
           oCfg:Fields:Update()

           nstep++  // Doing step 8
           oMsg = CREATEOBJECT( "CDO.Message" )

           nstep++  // Doing step 9
           oMsg:Configuration = oCfg

           IF !EMPTY( cSender ) THEN cFrom = ["] + cSender + ["] + " <" + cFrom + ">"

           nstep++  // Doing step 10
           oMsg:From    = cFrom
           oMsg:To      = cTo
           oMsg:Subject = cSubject

           nstep++  // Doing step 11

           IF !EMPTY( aCc )
               FOR i = 1 TO LEN( aCc )
                   IF i > 1 THEN cCc += ";"
                   cCc += aCc[ i ]
               NEXT
               oMsg:CC = cCc
           ENDIF
           nstep++ //Doing step 12
           IF !lHtml
               oMsg:TextBody = cMessage
           ELSE
               oMsg:HTMLBody = cMessage
           ENDIF

           nstep++ //Doing step 13
           IF !EMPTY( aAttach )
               FOR i = 1 TO LEN( aAttach )
                   cFilNam := alltrim( aAttach[i] )
                   IF EMPTY(cFilNam)
                     LOOP
                   ENDIF
                   ? " About to Attach ***" + cFilNam +"**"
                   oMsg:AddAttachment( cFilNam )
                   ?
               NEXT

           ENDIF
           nstep++   // Doing step 14
           IF lNotification
               oMsg:Fields( "urn:schemas:mailheader:disposition-notification-to" ):Value = cFrom
           ENDIF
           lTryInit := .T. // try to ignore all unnecessary steps
         ELSE
           oMsg:To      = cTo
           ? " Just set the oMsg:To vrbl this time"
         ENDIF


         nstep++ // Doing step 15
         oMsg:Send()
         ?
         ? " Sent Message to "+ cTo+ " at step "+NTOC(nstep)

         lOk = .T.
      NEXT      // end of the next loop

    CATCH
      lGotErr := .T.

      //alert("Step "+NTOC(nstep)+ " gave a Runtime Error. lGotErr = " +LTOC(lGotErr))

      ? " Runtime Error in Email at step "+NTOC(nstep)

    END

    RETURN lOk

**********

Miroslav Georgiev

unread,
Jan 3, 2021, 4:17:43 PM1/3/21
to Harbour Users
Hi all. Some recent antivirus apps block OLE.

Miroslav Georgiev

unread,
Jan 3, 2021, 4:27:20 PM1/3/21
to Harbour Users
Hi Nenad, please check Outlook's ActiveX settings:

Lately it's a common practice to restrict Office's ActiveX for security reasons. 

Mel Smith

unread,
Jan 3, 2021, 4:37:46 PM1/3/21
to Harbour Users
I have successfully used the "less-secure apps" feature on my primary and newly created send GMAIL Address. It was a real 'head-scratcher' to do though.
-Mel

Mel Smith

unread,
Jan 3, 2021, 6:24:53 PM1/3/21
to Harbour Users
Hi All: 
   Typo :  CDO means "Collaboration Data Objects"
-Mel

Nenad Batocanin

unread,
Jan 3, 2021, 7:13:12 PM1/3/21
to harbou...@googlegroups.com

Thank you, I use CDO as well as HB_SendMail but I need a way to send email via a _local_ email client (OLE or MAPI).

 

Regards, NB

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/01183d71-9081-44c0-99f6-7da2e089b132n%40googlegroups.com.

Nenad Batocanin

unread,
Jan 3, 2021, 7:13:12 PM1/3/21
to harbou...@googlegroups.com

Thank you Miroslav, the problem is probably here. But I use Outlook 2013, and he doesn't have these settings!

 

 

From: harbou...@googlegroups.com [mailto:harbou...@googlegroups.com] On Behalf Of Miroslav Georgiev
Sent: Sunday, January 3, 2021 10:27 PM
To: Harbour Users <harbou...@googlegroups.com>
Subject: [harbour-users] Re: Outlook OLE

 

Hi Nenad, please check Outlook's ActiveX settings:

--

--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.

image001.jpg

Auge & Ohr

unread,
Jan 6, 2021, 7:46:04 PM1/6/21
to Harbour Users
hi,

you are talking about MAPI to store Email to "Out-Basket"
what OS() ? 32 or 64 Bit ? (Office / your App )

greetings
Jimmy

Nenad Batocanin

unread,
Jan 6, 2021, 7:53:17 PM1/6/21
to harbou...@googlegroups.com

Hello!

 

I want to use both MAPI and OLE. I've been using them for years, but lately it's getting harder. I'm talking about users' computers, it's mostly about Win 10, different versions of the office.

 

Regards, NB

 

 

 

From: harbou...@googlegroups.com [mailto:harbou...@googlegroups.com] On Behalf Of Auge & Ohr
Sent: Thursday, January 7, 2021 1:46 AM
To: Harbour Users <harbou...@googlegroups.com>
Subject: [harbour-users] Re: Outlook OLE

 

hi,

--

--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.

Auge & Ohr

unread,
Jan 6, 2021, 8:46:57 PM1/6/21
to Harbour Users
hi,

i have used Xbase++ 32 Bit before which can NOT Access 64 Bit DLL or ActiveX !
so if your Customer have Office 64 Bit you have IHMO to use 64 Bit harbour App

---

under Xbase++ many have used SOCmapi.DLL (32 Bit) but since Windows 10 there is a "Right" Problem.

---

have you Try "mailto" ?
it will open Editor of Mail App

ACTION ShellExecute( 0, "open", "rundll32.exe", ;
"url.dll,FileProtocolHandler " + ;
"mailto:Auge...@Web.DE" + ;
"&subject=HBFM%20" + cVersion + "%20Feedback:" + ;
"&body= ",, 1 )

Cursor now is in empty "Body" ... so you can "paste" what you want ;)
Reply all
Reply to author
Forward
0 new messages