FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour pop up Outlook send email window
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
pop up Outlook send email window
Posted: Fri Dec 12, 2014 04:23 PM

Any Outlook user here knows how to popup the Outlook send email dialog programmatically ?

thanks! :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: pop up Outlook send email window
Posted: Fri Dec 12, 2014 05:50 PM
Antonio,

Can this code help you?
Code (fw): Select all Collapse
TRY
   GetActiveObject("Outlook.Application")
CATCH
   ShellExecute(,"Open","Outlook",,,3)
END
TRY
   oOutLook   := TOleAuto():New("Outlook.Application")
   oNameSpace := oOutlook:GetNameSpace("MAPI")
   EmSend     := .T.
CATCH
   EmSend     := .F.
END

IF EmSend

   TRY
      oMail  := oOutLook:CreateItem(olMailItem)
      EmSend := .T.
   CATCH
      TRY
         oMail  := oOutLook:CreateItem(olMailItem)
         EmSend := .T.
      CATCH
         EmSend := .F.
      END
   END

   IF EmSend
      oMail:Subject := cSubJect
      oMail:Body    := FmText
      dEmail := {}
      FOR i=1 TO LEN(cEmail) // cEmail = list of e-mail addresses in one variable
          SplitsEm := ALLTRIM(cEmail[i])
          DO WHILE AT(";",SplitsEm) <> 0
              EmSplits := ALLTRIM(LEFT(SplitsEm,AT(";",SplitsEm)-1))
              Aadd(dEmail,EmSplits)
              SplitsEm := ALLTRIM(RIGHT(SplitsEm,LEN(SplitsEm)-AT(";",SplitsEm)))
          ENDDO
          IF !EMPTY(SplitsEm)
              Aadd(dEmail,SplitsEm)
          ENDIF
      NEXT
      TRY
         FOR i=1 TO LEN(dEmail)
             oMail:Recipients:Add(dEmail[i])
         NEXT
      CATCH
         MsgAlert("An error occured in one of the e-mail addresses !!!"+CHR(13)+CHR(13)+"Check and try again.","Be careful")
         EmSend  := .F.
         EmAlert := .F.
      END
      IF EmSend
         IF !EMPTY(TabCC)  ; oMail:CC  := TabCC  ; ENDIF
         IF !EMPTY(TabBCC) ; oMail:BCC := TabBCC ; ENDIF
         TRY
            FOR i=1 TO LEN(TabBijl)
                oMail:Attachments:Add(TabBijl[i])
            NEXT
            EmSend := .T.
         CATCH
            TRY
               FOR i=1 TO LEN(TabBijl)
                   oMail:Attachments:Add(TabBijl[i])
               NEXT
               EmSend := .T.
            CATCH
               EmSend := .F.
            END
         END
      ENDIF
   ENDIF

   IF EmSend
      oMail:Save()
      IF !cRchtStr .AND. US->UOUTLSHW
         TRY
            oMail:DisPlay() // to display a e-mail in Outlook before it is send.
         CATCH
            TRY
               oMail:Display()
            CATCH
               EmSend := .F.
            END
         END
      ELSE
         TRY
            oMail:Send()
         CATCH
            TRY
               oMail:Send()
            CATCH
               EmSend := .F.
            END
         END
      ENDIF
   ENDIF

ENDIF

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: pop up Outlook send email window
Posted: Fri Dec 12, 2014 05:59 PM
Not sure exactly what you want but this is a sample send mail routine.

Code (fw): Select all Collapse
METHOD Email( cTo, aFiles )
   local oOutlook, oEmail
   local oMyAttachments, nNoAttachments
   local cSubject
   local cBody
   local cHtml
   local cTextColor := "004000"
   local cTextName := "Times New Roman"
   if aFiles == nil
      aFiles := {}
   endif
   oOutlook = CREATEOBJECT( "Outlook.Application" )
   oEMail = oOutlook:CreateItem( 0 )         // #define olMailItem 0
   If valtype( oEMail ) != "O"
      MsgInfo("There is no active inspector.")
      return nil
   endif
   oEMail:Recipients:Add( cTo )
   oEmail:BodyFormat := 2  // olFormatHTML : 2: olFormatPlain : 1: olFormatRichText : 3
   cSubject := 'Test Document'

   // Attachments
   for nCounter := 1 to len( aFiles )
      if file( aFiles[ nCounter ] )
         // oMail:Attachments:Add(  cFilePath+cFileName, olByValue, 1, cFileName )
         oEMail:Attachments:Add( aFiles[ nCounter ] )
      endif
   next

   cHtml := [<html lang="en">]+CRLF
   cHtml += [<head>]+CRLF
   cHtml += [<meta http-equiv="Content-Language" content="en-us">]+CRLF
   cHtml += [<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">]+CRLF
   cHtml += [<title>]+'Test Sending Email'+[</title>]+CRLF
   cHtml += [</head>]+CRLF
   cHtml += [<body>]+CRLF
   cHtml += [<basefont face="]+cTextName+[,arial, verdana, courier" size="2" color="#]+cTextColor+[">]+CRLF
   cHtml += [<br>]+CRLF

   cHtml += [All body goes here]+CRLF

   cHtml += [<br>&nbsp;</body>]+CRLF
   cHtml += [</html>]

   //    oMail:HTMLBody = MEMOREAD( "test.htm" )
   oEMail:HTMLBody := cHtml
   oEMail:Display = .T.
   oEMail := nil
   oOutlook := nil
RETURN nil
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: pop up Outlook send email window
Posted: Fri Dec 12, 2014 07:40 PM

If Outlook is installed, and I use this MAPI function, the email dialog from Outlook pops up for editing and final Send:

FUNCTION SendMAPIMail2( MailTo, cSndFile, cText, cSubj )
LOCAL oMail

  DEFINE MAIL oMail ;
     SUBJECT cSubj ;
     TEXT cText ;
     FILES cSndFile, cSndFile ;
     FROM USER ;
     TO MailTo

  ACTIVATE MAIL oMail

RETURN( .t. )

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: pop up Outlook send email window
Posted: Fri Dec 12, 2014 08:39 PM

Guys,

But now another question.

How do you get received e-mails into your FWH-application?

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: pop up Outlook send email window
Posted: Sat Dec 13, 2014 05:49 AM

Thank you so much! :-)

For now, I think this is what I was looking for:

// oMail:Save() maybe

oMail:Display()

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 99
Joined: Mon Aug 09, 2010 11:00 AM
Re: pop up Outlook send email window
Posted: Sat Dec 13, 2014 08:05 AM

http://www.afterlogic.com/mailbee/objects

I use it since a long time

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: pop up Outlook send email window
Posted: Sat Dec 13, 2014 08:23 AM

Uwe,

many thanks for the info.

You all know that I don't enjoy using third party products beside FWH, if possible :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: pop up Outlook send email window
Posted: Sat Dec 13, 2014 09:10 AM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: pop up Outlook send email window
Posted: Sat Dec 13, 2014 09:34 AM

I always get an error here:

oMail:Recipients:Add( "test@test.com" )

but

oMail:Subject = "test"

works fine

Any hints ? thanks :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: pop up Outlook send email window
Posted: Sat Dec 13, 2014 09:52 AM
Antonio,

that's strange. It looks like the corrent syntax:

http://msdn.microsoft.com/en-us/library/office/ff866751(v=office.15).aspx

EMG
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: pop up Outlook send email window
Posted: Sat Dec 13, 2014 09:59 AM

Enrico,

Could you try it there using Harbour ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: pop up Outlook send email window
Posted: Sat Dec 13, 2014 10:09 AM

Antonio,

yes, I get the same error with both Harbour and xHarbour. :-(

EMG

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: pop up Outlook send email window
Posted: Sat Dec 13, 2014 10:18 AM

Any other user could confirm this ?

Thanks! :-)

:-(

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 310
Joined: Mon Oct 10, 2005 05:10 AM
Re: pop up Outlook send email window
Posted: Sun Dec 14, 2014 12:25 AM
Hi Antonio

This works fine with Harbour
Code (fw): Select all Collapse
function fnEmail(cTo,cSentBy,cEmailHeader,cEmailNotes,cPdf)
oOutLook := TOleAuto():New("Outlook.Application")
oMailItem := oOutLook:Invoke("CreateItem", 0) 
oMailitem:to:=cTo
oMailItem:Recipients:Add( "tdsperth@outlook.com" )
oMailitem:CC:= cSentBy
oMailItem:Subject := cEmailHeader
oMailItem:Body := cEmailNotes
if ! empty(cPdf)
   oMailItem:Attachments:Add(cPdf)
endif
oMailItem:display(.T.)

return(nil)


cheers

Colin