danielmaximiliano wrote:
need to create the inclusion of multiple attachments and problem solved.
Hi :
Translate google :
I solved part of TipMail File Inclusion.
Selecting a file that is sent without compression, but if you select multiple files these are compressed by hbmzip, it is created in the folder where the application is launched.
still have not found it does not attach the Zip file and any other ZIP, you may have a lot of sleep and, if anyone wants to correct this problem would be great.
Español :
Resolvi parte de la inclusión de archivos en TipMail.
al Seleccionar un archivo este se envia sin compresion, pero si se selecciona varios archivos estos se comprimen mediante hbmzip, el mismo se crea en la carpeta donde se lanza la aplicacion.
todavia no encontre porque no se adjunta el Zip y cualquier otro archivo ZIP, puede ser que tenga mucho sueño ya, si alguno quiere corregir este problema sería muy bueno.
Code: Select all
#include 'hmg.ch'
#require "hbtip"
#include "hbmzip.ch"
Function Main
Public lSend := .F.
Public cSubject := "TIpClientSmtp()"
Public cFrom := 'userid'
Public cTo := 'userid@server.com' //
Public cBody := 'This is a test mail sent at : ' + DtoC(date()) + ' ' + Time()
Public oConnection , oMail , oAttachments
Public cUserId , cPassword , cUrl , cProto , cServer := ''
Public cFilePath , cFileName , cFileExt
Public CurDirectory := Curdir()
cProto := "smtp://"
cServer := "smtp.gmail.com"
cUserId := "UserID"
cPassword := "UserPass"
cUrl := cProto + cUserId + ":" + cPassword + "@" + cServer
/* .T. Trace in smtp-x.log */
oConnection := TIpClientSmtp():new( cUrl , .T. )
IF .NOT. oConnection:open()
MsgInfo( "Connection error : " + oConnection:lastErrorMessage()+ chr(10) +;
"Try again or bad Pass/User " , " ¡¡ Message Error !! " )
Quit
Endif
If ( oConnection:auth( cUserId , cPassword ) )
/* Create Email */
oMail := TIpMail():new( hb_StrToUTF8( cBody ) )
oMail:hHeaders[ "Content-Type" ] := "text/plain; charset=utf-8"
oMail:hHeaders[ "Date" ] := tip_TimeStamp()
oMail:hHeaders[ "From" ] := hb_StrToUTF8( cFrom )
oMail:hHeaders[ "To" ] := hb_StrToUTF8( cTo )
oMail:hHeaders[ "Subject" ] := hb_StrToUTF8( cSubject )
/* create attach */
If MsgYesNo("¿ Attach Files ?")
AddAttachment()
Endif
/* Send Email */
lSend := oConnection:sendMail( oMail )
If lSend
MsgInfo( "Send Sucefully : " , " ¡¡ Message Info !! " )
Else
MsgInfo( "Send Failed : " + oConnection:lastErrorMessage() + chr( 13 ) + chr(10) +;
"Try again " , " ¡¡ Message Error !! " )
Quit
endif
Else /* Fail Auth */
MsgInfo( "Auth Failed : " + oConnection:lastErrorMessage() + chr( 13 ) + chr(10) +;
"Try again, Bad Id or Pass " , " ¡¡ Message Error !! " )
Endif
RETURN Nil
*------------------------------------------*
function AddAttachment()
*------------------------------------------*
local aFiles , aArchives := {}
local nI , hZip , cArq
Local cComment := "Multiple Files in Zip"
Local FileNameZip := DiskName() + ":\" + CurDirectory + "\Attachment.zip"
/* Search Files */
aFiles := Getfile ( { {'All Files','*.*'} } , 'Get attachment' , 'c:\' , .t. , .t. )
For nI:=1 to len( aFiles )
hb_FNameSplit( aFiles [ nI ] ,@cFilePath , @cFileName, @cFileExt )
aadd(aArchives , cFilePath + cFileName + cFileExt )
next
If len( aFiles ) > 0
If len( aFiles ) == 1
Mailattachment( cFilePath + cFileName + cFileExt )
Else
hZip := HB_ZIPOPEN( FileNameZip )
FOR EACH cArq IN aArchives
HB_ZipStoreFile( hZip, cArq , cComment)
NEXT
HB_ZipFileClose( hZip )
Mailattachment( FileNameZip )
Endif
oMail:attach( oAttachments )
Endif
Return
*------------------------------------------*
Function Mailattachment( cData )
*------------------------------------------*
// Create Attachment
msginfo( "Send : " + cData )
oAttachments := TIpMail():new()
// TODO: mime type magic auto-finder
oAttachments:SetEncoder( "base64" )
// Some EMAIL readers use Content-Type to check for filename
oAttachments:hHeaders[ "Content-Type" ] := ;
"application/X-TIP-Attachment; filename=" + cData
// But usually, original filename is set here
oAttachments:hHeaders[ "Content-Disposition" ] := "attachment; filename=" + cData
oAttachments:SetBody( cData )
Return