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
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> </body>]+CRLF
cHtml += [</html>]
// oMail:HTMLBody = MEMOREAD( "test.htm" )
oEMail:HTMLBody := cHtml
oEMail:Display = .T.
oEMail := nil
oOutlook := nil
RETURN nil
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)
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 46 guests