by Marco Turco » Tue Oct 27, 2009 12:40 pm
Hi,
this routine will use Outlook via OLE if available otherwise the default mail client.
#include "FiveWin.ch"
#include "Mail.ch"
FUNCTION Interactivemessage()
paramet cSubject, cBody, aTo, aFiles, lDirectSend,lUseCC
LOCAL oOutLook,oMailItem,oRecip,oAttach,i,lOffice,lMailMancante,cVar
local nSelected,oDlg1
if lUseCC=NIL
lUseCC:=.f.
endif
if lDirectSend=NIL
lDirectSend:=.f.
endif
if cSubject=NIL
cSubject:=""
endif
if cBody=NIL
cBody:=""
endif
if aFiles=NIL
aFiles:=array(0,0)
endif
lMailMancante:=.f.
for i:=1 to len(aTo)
if len(alltrim(aTo[i,2]))=0
lMailMancante:=.t.
endif
next
if lMailMancante
MsgStop("Indirizzo di posta elettronica assente","Attenzione")
return
endif
lOffice:=.t.
TRY
oOutLook := CreateObject( "Outlook.Application" )
oMailItem := oOutLook:CreateItem( 0 )
oRecip := oMailItem:Recipients
CATCH
lOffice:=.f.
END
****
if lOffice
if lUseCC
cVar:=""
for i:=1 to len(aTo)
cVar:=cVar+aTo[i,2]+";"
next
oMailItem:Bcc:=cVar
else
for i:=1 to len(aTo)
oRecip:Add( aTo[i,2] )
next
endif
oMailItem:Subject := cSubject
oMailItem:Body := cBody
if len(aFiles)>0
oAttach := oMailItem:Attachments
for i:=1 to len(aFiles)
oAttach:Add( aFiles[i,1] )
next
endif
if lDirectSend
oMailItem:Send()
else
oMailItem:display(.t.)
endif
else
for i:=1 to len(aTo)
aTo[i,1]:=alltrim(aTo[i,2])
aTo[i,2]:=alltrim(aTo[i,2])
next
oMail:=tMail():New( cSubject,cBody,,,,, .f., .t.,,aTo,aFiles)
ACTIVATE MAIL oMail
retcode:=oMail:nRetCode
do case
case retcode=1
MsgStop("Invio interrotto dall'utente","Errore")
case retcode=9
MsgStop("Troppi files da inviare","Errore")
case retcode>0
MsgStop("Errore nell'invio della mail ("+alltrim(str(retcode,3))+")","Errore")
endcase
endif
return
Best Regards,
Marco Turco
SOFTWARE XP LLP