I'm using Sendmail() to send a mail and attach a pdf file, but i find the
attach at the end of the body of the email in this way :
--=_0EFRGQKGTHILTWDHYS_TIP_22-10-2007_143021
Content-Disposition: attachment; filename=FT-2007-3.pdf
Content-transfer-encoding: Base64
Content-Type: application/pdf;filename=FT-2007-3.pdf
JVBERi0xLjMNCjIgMCBvYmoNCjw8DQovVHlwZSAvUGFnZSAvUGFyZW50IDEgMCBSDQovUmVz
b3VyY2VzIDMgMCBSDQovTWVkaWFCb3ggWyAwIDAgNjEyLjAwIDc5Mi4wMCBdDQovQ29udGVu
.......
what's wrong?
Many thanx!
Roberto
sendmail from cvs?
Regards
Luiz
Luiz
no, it is not the version from CVS but an old version the you posted a
couple of years ago.
It seems to me that it stops working when I upgrade form xHarbour 99.50 to
99.70.
Is it possible?
BTW I never used CVS version because in xHarbour.org site there is this
warning:
"It is strongly encouraged to ONLY use STABLE xHarbour builds ......"
(http://www.xharbour.org/index.asp?page=developers/index)
but unfortunatelly downlodable binaries for BCC are of december 2006.
Many thanks!
Regards,
Roberto
/* Author Luiz Rafael Culik Guimaraes luiz at xharbour.com.br */
#include "common.ch"
//FUNC main
//local n
//for n:=1 to 1
//
QOut(SendMail("xxxxx",,"xxxxx",{"cul...@brturbo.com.br"},"xxxx","Error.log",,"xxxx","xxxx",[xxxxxxx],,,.t.,.t.)
)
//next
//inkey(10)
//altd()
// ? recvMail( [smtp.brturbo.com.br],,[cul...@brturbo.com.br] ,
{[cul...@brturbo.com.br]},[Erro], [Error.log],{'autocom.zip'} , [culikr],
[xxxxxxxx],[xxxxxxxxxxxxxxxxxx],,,.t.,.t.)
//RETURN nil
*+北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北
*+
*+ Function SendMail()
*+ Parameters
*+ cServerIP -> Required. Smtp server name or address
*+ nPort -> Optional. Stmt port number
*+ cFrom -> Required. Email Address of who is sending
*+ aTo -> Required. an simple email Address, or an array
containing multiples reciepts email address
*+ cMsg -> Optional. Message Body For html emails, pass the html
filename as subject
*+ cSubject -> Optional. Message subject
*+ aFiles -> Optional. Array of files to attach to email
*+ cUser -> Required. Pop3 user name
*+ cPass -> Required. Pop user name password
*+ cPopServer -> Required. Pop3 server name or address
*+ nPriority -> Optional. Email Prioryty. 1 high 3[default] normal 5
lower
*+ lRead -> Optional. Flag to indicate is user need to confirm
reciept . default .f.
*+ lTrace -> Optional. Flag to indicate creation of log files
(sendmail*.log) . default .f.
*+ lPopAuth -> Optional. Flag to indicate to authenticate via pop3
server. Default .T.
*+北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北
*+
FUNCTION SendMail( cServerIP, nPort, cFrom, aTo, cMsg, cSubject, aFiles,
cUser, cPass, cPopServer, nPriority, lRead, lTrace ,lPopAuth )
LOCAL oInMail
LOCAL lSair := .F.
LOCAL nStart
LOCAL nRetry := 1
LOCAL oUrl
LOCAL oUrl1
LOCAL oMail
LOCAL cTo := ""
LOCAL aThisFile
LOCAL cFile
LOCAL cData2
LOCAL cFname
LOCAL cFext
LOCAL cData
LOCAL cConnect := ""
LOCAL CC := ""
LOCAL lRet := .T.
LOCAL oPop
LOCAL lSecure := .F.
LOCAL lAuthLogin := .F.
LOCAL lAuthPlain := .F.
LOCAL lConnect := .T.
LOCAL cMimeText := ""
LOCAL lConnectPlain := .f.
Local cMsgTemp
local cLastError, oAttach
DEFAULT cUser TO ""
DEFAULT cPass TO ""
DEFAULT nPort TO 25
DEFAULT aFiles TO {}
DEFAULT nPriority TO 3
DEFAULT lRead TO .f.
DEFAULT lTrace to .F.
DEFAULT lPopAuth to .T.
cLastError := ""
cUser := Strtran( cUser, "@", "&at;" )
IF Valtype( aTo ) == "A"
IF Len( aTo ) > 1
FOR EACH cTo IN aTo
IF HB_EnumIndex() != 1
cC += cTo + ","
ENDIF
NEXT
cC := Substr( cC, 1, Len( cC ) - 1 )
ENDIF
cTo := aTo[ 1 ]
IF Len( cC ) > 0
cTo += "," + cC
ENDIF
ELSE
cTo := Alltrim( aTo )
ENDIF
//TraceLog(cServerIP, nPort, cFrom, aTo, cMsg, cSubject, aFiles, cUser,
cPass, cPopServer, nPriority, lRead, lTrace ,lPopAuth)
//tracelog(cUser)
// This is required. Many smtp server, requires that first user connect
to popserver, to validade user, and the allow smtp access
IF cPopServer != NIL .AND. lPopAuth
oUrl1 := tUrl():New( "pop://" + cUser + ":" + cPass + "@" + cPopServer
+ "/" )
oUrl1:cUserid := Strtran( cUser, "&at;", "@" )
if "gmail" in lower(cPopserver)
oUrl1:nPort := 995
endif
oPop := tIPClient():new( oUrl1,, lTrace )
if oPop:Open()
oPop:Close()
ENDIF
ENDIF
cConnect := "smtp://" + cUser + "@" + cServerIp + '/' + cTo
oUrl := tUrl():New( cConnect )
cUser := Strtran( cUser, "&at;", "@" )
oUrl:nPort := nPort
oUrl:cUserid := cUser
oMail := TipMail( ):new()
oAttach := Tipmail():new()
oAttach:setEncoder( "7-bit" )
IF (".htm" IN Lower( cMsg ) .OR. ".html" IN Lower( cMsg ) ) .and.
File(cMsg)
cMimeText := "text/html ; charset=ISO-8859-1"
oAttach:hHeaders[ "Content-Type" ] := cMimeText
cMsgTemp := cMsg
cMsg := MemoRead( cMsgTemp )
else
oMail:hHeaders[ "Content-Type" ] := "text/plain; charset=iso8851"
ENDIF
oAttach:setbody( cmsg )
oMail:attach( oAttach )
oUrl:cFile := cTo
oMail:hHeaders[ "Date" ] := Tip_Timestamp()
oMail:hHeaders[ "From" ] := cFrom
oInMail := tIPClient():new( oUrl,, lTrace )
IF oInMail:Opensecure()
WHILE .T.
oInMail:GetOk()
IF oInMail:cReply == NIL
EXIT
ELSEIF "LOGIN" IN oInMail:cReply
lAuthLogin := .T.
ELSEIF "PLAIN" IN oInMail:cReply
lAuthPlain := .T.
ENDIF
ENDDO
IF lAuthLogin
IF !oInMail:Auth( cUser, cPass )
lConnect := .F.
//oInMail:Quit()
ELSE
lConnectPlain := .t.
ENDIF
ENDIF
IF lAuthPlain .AND. !lConnect
IF !oInMail:AuthPlain( cUser, cPass )
lConnect := .F.
//oInMail:Quit()
ENDIF
ELSE
IF !lConnectPlain
oInmail:Getok()
lConnect := .F.
ENDIF
ENDIF
ELSE
lConnect := .F.
ENDIF
IF !lConnect
//roby oInMail:close()
IF !oInMail:Open()
lConnect := .F.
//roby oInmail:close()
RETURN .F.
ENDIF
WHILE .T.
oInMail:GetOk()
IF oInMail:cReply == NIL
EXIT
ENDIF
ENDDO
ENDIF
oInMail:oUrl:cUserid := cFrom
oMail:hHeaders[ "To" ] := cTo
oMail:hHeaders[ "Subject" ] := cSubject
FOR EACH aThisFile IN AFiles
IF Valtype( aThisFile ) == "C"
cFile := aThisFile
cData := Memoread( cFile )
ELSEIF Valtype( aThisFile ) == "A" .AND. Len( aThisFile ) >= 2
cFile := aThisFile[ 1 ]
cData := aThisFile[ 2 ]
ELSE
lRet := .F.
EXIT
ENDIF
oAttach := TipMail():New()
//TODO: mime type magic auto-finder
HB_FNameSplit( cFile,, @cFname, @cFext )
IF Lower( cFile ) LIKE
".+\.(zip|jp|jpeg|png|jpg|pdf|bin|dms|lha|lzh|exe|class|so|dll|dmg)" .or.
Empty(cFExt)
oAttach:SetEncoder( "base64" )
ELSE
oAttach:SetEncoder( "7-bit" )
ENDIF
cMimeText := SetMimeType( cFile, cFname, cFext )
// Some EMAIL readers use Content-Type to check for filename
IF ".html" in lower( cFext) .or. ".htm" in lower( cFext)
cMimeText += "; charset=ISO-8859-1"
ENDIF
oAttach:hHeaders[ "Content-Type" ] := cMimeText
// But usually, original filename is set here
oAttach:hHeaders[ "Content-Disposition" ] := ;
"attachment; filename=" + cFname + cFext
oAttach:SetBody( cData )
oMail:Attach( oAttach )
NEXT
IF lRead
oMail:hHeaders[ "Disposition-Notification-To" ] := cUser
ENDIF
IF nPriority != 3
oMail:hHeaders[ "X-Priority" ] := Str( nPriority, 1 )
ENDIF
lRet := .T.
IF lRet
cData2 := oMail:ToString()
oInmail:Write( cData2 )
oInMail:commit()
ENDIF
//oInMail:quit()
oInMail:close()
IF lRet
cLastError := ""
ENDIF
RETURN lRet
*+北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北
*+
*+ Function SetMimeType()
*+
*+北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北
*+
FUNCTION SetMimeType( cFile, cFname, cFext )
cFile := Lower( cFile )
IF cFile LIKE ".+\.zip"
RETURN "application/x-zip-compressed;filename=" + cFname + cFext
ELSEIF cFile LIKE ".+\.(jpeg|jpg|jp)"
RETURN "image/jpeg;filename=" + cFname + cFext
ELSEIF cFile LIKE ".+\.(png|bmp)"
RETURN "image/png;filename=" + cFname + cFext
ELSEIF cFile LIKE ".+\.(bmp)"
RETURN "image/bitmap;filename=" + cFname + cFext
ELSEIF cFile LIKE ".+\.html?"
RETURN "text/html;filename=" + cFname + cFext
ELSEIF cFile LIKE ".+\.pdf"
RETURN "application/pdf;filename=" + cFname + cFext
ELSEIF cFile LIKE ".+\.txt"
RETURN "test/plain;filename=" + cFname + cFext
ELSEIF cFile LIKE ".+\.(bin|dms|lha|lzh|exe|class|so|dll|dmg)" .or.
Empty(cFExt)
RETURN "application/octet-stream;filename=" + cFname + cFext
ENDIF
RETURN "text/plain;filename=" + cFname + cFext
*+ EOF: MAIL1.PRG
FUNCTION recvMail( cServerIP, nPort, cFrom, aTo, cMsg, cSubject, aFiles,
cUser, cPass, cPopServer, nPriority, lRead, lTrace ,lPopAuth)
LOCAL oInMail
LOCAL lSair := .F.
LOCAL nStart
LOCAL nRetry := 1
LOCAL oUrl
LOCAL oUrl1
LOCAL oMail
LOCAL cTo := ""
LOCAL aThisFile
LOCAL cFile
LOCAL cData2
LOCAL cFname
LOCAL cFext
LOCAL cData
LOCAL cConnect := ""
LOCAL CC := ""
LOCAL lRet := .T.
LOCAL oPop
LOCAL lSecure := .F.
LOCAL lAuthLogin := .F.
LOCAL lAuthPlain := .F.
LOCAL lConnect := .T.
LOCAL cMimeText := ""
LOCAL lConnectPlain := .f.
Local cMsgTemp
local cLastError
DEFAULT cUser TO ""
DEFAULT cPass TO ""
DEFAULT nPort TO 25
DEFAULT aFiles TO {}
DEFAULT nPriority TO 3
DEFAULT lRead TO .f.
DEFAULT lTrace to .F.
DEFAULT lPopAuth to .T.
cLastError := ""
cUser := Strtran( cUser, "@", "&at;" )
IF Valtype( aTo ) == "A"
IF Len( aTo ) > 1
FOR EACH cTo IN aTo
IF HB_EnumIndex() != 1
cC += cTo + ","
ENDIF
NEXT
cC := Substr( cC, 1, Len( cC ) - 1 )
ENDIF
cTo := aTo[ 1 ]
IF Len( cC ) > 0
cTo += "," + cC
ENDIF
ELSE
cTo := Alltrim( aTo )
ENDIF
// This is required. Many smtp server, requires that first user connect
to popserver, to validade user, and the allow smtp access
IF cPopServer != NIL .AND. lPopAuth
oUrl1 := tUrl():New( "pop://" + cUser + ":" + cPass + "@" + cPopServer
+ "/" )
oUrl1:cUserid := Strtran( cUser, "&at;", "@" )
oPop := tIPClient():new( oUrl1,, lTrace )
IF oPop:Open()
? opop:list()
oPop:Close()
ENDIF
ENDIF
return nil
>
I had a very similar problem recently when attaching an HTML file as the
message body. I contacted the xHarbour.com team about it and as I
understand it is now fixed but not available until the next release.
Kind regards,
Barry O'Brien
"bob" <seee_mo_che...@poste.it> wrote in message
news:ffil9o$ini$1...@nnrp.ngi.it...
I´ll post an updated version later today
Regards
Luiz
Fix on code bellow(just copy the content to an .prg)
Regards
luiz
IF HB_EnumIndex() != 1
ENDIF
NEXT
ENDIF
cTo := aTo[ 1 ]
ENDIF
ELSE
if oPop:Open()
oPop:Close()
ENDIF
ENDIF
cMsg := MemoRead( cMsgTemp ) + chr( 13 ) + chr( 10 )
IF oInMail:Opensecure()
WHILE .T.
oInMail:GetOk()
EXIT
lAuthLogin := .T.
lAuthPlain := .T.
ENDIF
ENDDO
IF lAuthLogin
ELSE
lConnectPlain := .t.
ENDIF
ENDIF
IF lAuthPlain .AND. !lConnect
ENDIF
ENDIF
ELSE
lConnect := .F.
ENDIF
IF !lConnect
//roby oInMail:close()
IF !oInMail:Open()
ENDIF
WHILE .T.
oInMail:GetOk()
EXIT
ENDIF
ENDDO
cFile := aThisFile
cData := Memoread( cFile ) + chr( 13 ) + chr( 10 )
ELSEIF Valtype( aThisFile ) == "A" .AND. Len( aThisFile ) >= 2
cFile := aThisFile[ 1 ]
cData := aThisFile[ 2 ] + chr( 13 ) + chr( 10 )
Regards,
Roberto
"luiz Rafael Culik Guimaraes" <lu...@xharbour.com.br> wrote in message
news:471e1707$0$1341$834e...@reader.greatnowhere.com...
Regatds,
Rob
"bob" <seee_mo_che...@poste.it> wrote in message
news:fg0asn$tme$1...@nnrp.ngi.it...
Is this last version of sendmail?
oInMail := tIPClient():new( oUrl,, lTrace )
IF oInMail:Opensecure()
Error BASE/1004 Message not found:
TIPCLIENT:OPENSECURE
Error at ...: SENDMAIL(698) in Module: SSMAIL.PRG
Called from : TIPCLIENT:MSGNOTFOUND(205) in Module: tobject.prg
Called from : TIPCLIENT:OPENSECURE(0) in Module: tobject.prg
Called from : SENDMAIL(698) in Module: SSMAIL.PRG
Called from : MAIN(76) in Module: SSMAIL.PRG
Operating system...: Windows XP Professional 5.01.2600 Service Pack 2
xHarbour version...: xHarbour build 1.0.0 Intl. (SimpLex)
xHarbour built on..: Nov 7 2007 10:23:23
C/C++ compiler.....: Borland C++ 5.5.1
Multi Threading....: NO
VM Optimization....: 2
if you are using cvs version, use the hb_sendmail from
source\tip\sendmail.prg
Regards
Luiz
Is this last version of sendmail?
no,this version is for 0.,99.70
Regards
Luiz