pop up Outlook send email window

pop up Outlook send email window

Postby Antonio Linares » Fri Dec 12, 2014 4:23 pm

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

thanks! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: pop up Outlook send email window

Postby driessen » Fri Dec 12, 2014 5:50 pm

Antonio,

Can this code help you?
Code: Select all  Expand view
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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: pop up Outlook send email window

Postby Gale FORd » Fri Dec 12, 2014 5:59 pm

Not sure exactly what you want but this is a sample send mail routine.

Code: Select all  Expand view

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

 
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: pop up Outlook send email window

Postby TimStone » Fri Dec 12, 2014 7: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
User avatar
TimStone
 
Posts: 2904
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: pop up Outlook send email window

Postby driessen » Fri Dec 12, 2014 8: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. 24.02 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc77
User avatar
driessen
 
Posts: 1396
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: pop up Outlook send email window

Postby Antonio Linares » Sat Dec 13, 2014 5: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: pop up Outlook send email window

Postby Uwe.Diemer » Sat Dec 13, 2014 8:05 am

User avatar
Uwe.Diemer
 
Posts: 93
Joined: Mon Aug 09, 2010 11:00 am

Re: pop up Outlook send email window

Postby Antonio Linares » Sat Dec 13, 2014 8: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: pop up Outlook send email window

Postby Antonio Linares » Sat Dec 13, 2014 9:10 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: pop up Outlook send email window

Postby Antonio Linares » Sat Dec 13, 2014 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Re: pop up Outlook send email window

Postby Antonio Linares » Sat Dec 13, 2014 9:59 am

Enrico,

Could you try it there using Harbour ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: pop up Outlook send email window

Postby Enrico Maria Giordano » Sat Dec 13, 2014 10:09 am

Antonio,

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: pop up Outlook send email window

Postby Antonio Linares » Sat Dec 13, 2014 10:18 am

:-(

Any other user could confirm this ?

Thanks! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: pop up Outlook send email window

Postby Colin Haig » Sun Dec 14, 2014 12:25 am

Hi Antonio

This works fine with Harbour
Code: Select all  Expand view


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
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 79 guests