Function Config_eMail(cdest, cfiles )
Local cUser,cPass,cRemt, cCC, cCCO, cTxt, cSubject
local lRet := .f.
local oCfg, oError
local cServ :=alltrim(correo:smtp) // aServs[nServ][2] //--> SERVIDOR SMTP - "smtp.servidor.com.br"
local nPort :=val(alltrim(correo:puerto)) // aServs[nServ][3]
local lAut :=.t.
local lSSL :=.f. // aServs[nServ][4]
public correo
if cfiles=nil
aAttach:={}
else
aAttach:=cfiles
endif
cPass:=alltrim(correo:contra)
cuser:=alltrim(correo:usuario)
ctxt:= correo:MENSA
csubject:=correo:texto
ccc:=""
ccco:=""
cRemt:=alltrim(correo:usuario)
// cdest:="chino72vale@hotmail.com" // ay que pasas esta informacion ok
cCC:=""
cCCO:=""
// aAttach:=CFILES // serian los archivos anexados we
if Empty(cPass) .or. Empty(cRemt) .or. empty(cDest)
? "falta datos para mandar correo,,,, destino/ remitente / usuario checar "
return .f.
endif
TRY
oCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT oCfg:Fields
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := cServ
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := nPort
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := 2
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := lAut
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := lSSL
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := cUser
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := cPass
:Update()
END WITH
lRet := .t.
CATCH oError
MsgInfo( "No se pudo enviar e-Mail!" +CRLF+ ;
"Error: " + Transform(oError:GenCode, nil) + ";" +CRLF+ ;
"SubC: " + Transform(oError:SubCode, nil) + ";" +CRLF+ ;
"OSCode: " + Transform(oError:OsCode, nil) + ";" +CRLF+ ;
"SubSystem: " + Transform(oError:SubSystem, nil) + ";" +CRLF+ ;
"Mensaje: " + oError:Description, "Atención" )
END
//--> FIM DAS CONFIGURAÇOES.
if lRet
lRet := Envia_eMail(oCfg,cRemt,cDest, cCC, cCCO, cTxt, cSubject)
endif
Return lRet
********************************************************************************
Function Envia_eMail(oCfg,cFrom, cTo, cCC, cBCC, cMsg, cSubject)
local cToken
local lRet := .f. , Omsg , x, i, loBP
TRY
oMsg := CREATEOBJECT ( "CDO.Message" )
WITH OBJECT oMsg
:Configuration = oCfg
:From = cFrom
:To = cTo
:CC = cCC
:BCC = cBCC
:Subject = cSubject
:TextBody = cMsg
For x := 1 To Len( aAttach )
if aAttach[x] <> NIL
:AddAttachment(AllTrim(aAttach[x]))
endif
Next
:HTMLBody = "<p><img src='cid:id_imagen10'></p>" +"<p>La imagen de arriba esta embebida en el mensaje.</p>"
loBP:=:AddRelatedBodyPart("c:\faceleben\kasto2.bmp", "id_imagen10", 1)
WITH OBJECT loBP:Fields
:Item("urn:schemas:mailheader:Content-ID") = "id_imagen10"
:Update()
END WITH
:CreateMHTMLBody("File://c:\faceleben\suave.html",0)
:Send()
END WITH
lRet := .t.
CATCH
// MsgInfo("No se pudo mandar la factura ")
lRet := .f.
END
Return lRet
Function CDOSendMail( aTabMail )
Local oEmailCfg,oEmailMsg
TRY
oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT oEmailCfg:Fields
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := TRIM( aTabMail[01] ) //"mail.xxxxxxxx.com"
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := aTabMail[11] // 25
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := 2 // Remote SMTP = 2, local = 1
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := aTabMail[08] // .T.
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := .T.
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := TRIM( aTabMail[09] ) // "xxanser@xxxxxxxx.com"
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := TRIM( aTabMail[10] ) // "xxxxxx"
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 30
:Update()
END WITH
CATCH oError
MsgInfo( "Could not create message configuration" + ";" + ;
"Error: " + TRANSFORM(oError:GenCode, NIL) + ";" + ;
"SubC: " + TRANSFORM(oError:SubCode, NIL) + ";" + ;
"OSCode: " + TRANSFORM(oError:OsCode, NIL) + ";" + ;
"SubSystem: " + TRANSFORM(oError:SubSystem, NIL) + ";" + ;
"Message: " + oError:Description )
Return .F.
END
oError:=NIL
TRY
oEmailMsg := CREATEOBJECT ( "CDO.Message" )
WITH OBJECT oEmailMsg
:Configuration = oEmailCfg
:From = aTabMail[02] //chr(34)+" Anser K.K. "+chr(34)+ "<anser@xxxxxxxx.com>" // This will be displayed in the From (The email id does not appear)
:To = TRIM( aTabMail[03] ) // "xxanserkk@xxxxx.com" // <----- Place the TO email address
:Subject = aTabMail[04] // "This is a Tst message"
//:ReplyTo = aTabMail[02] //"xxanser@xxxxxxxxx.com"
//:Sender = aTabMail[02] //"xxanser@xxxxxxxxx.com" // Read Receipt message is send to this
//:Organization = TRIM( aTabMail[02] ) // "My xxxxxx Company" // "My Company Name"
:MDNRequested = .T.
:HTMLBody = "<HTML> " + TRIM( aTabMail[05] ) + " </HTML>"
IF LEN( aTabMail[06] ) > 0
For nEle := 1 To Len( aTabMail[06] )
:AddAttachment( ALLTRIM(aTabMail[06][nEle] )) // := AllTrim( aAttach[ nEle ] )
Next
ENDIF
:Send()
END WITH
SysRefresh()
CATCH oError
MsgInfo( "Could not send message" + ";" + CRLF+ ;
"Error: " + TRANSFORM(oError:GenCode, NIL) + ";" + CRLF+;
"SubC: " + TRANSFORM(oError:SubCode, NIL) + ";" + CRLF+ ;
"OSCode: " + TRANSFORM(oError:OsCode, NIL) + ";" + CRLF +;
"SubSystem: " + TRANSFORM(oError:SubSystem, NIL) + ";" +CRLF+ ;
"Message: " + oError:Description )
Return .F.
END
Return( .t. )
' Configura las opciones para el login en el SMTP
If Usar_Autentificacion Then
' Id de usuario del servidor Smtp ( en el caso de gmail, debe ser la dirección de correro _
mas el @gmail.com )
Obj_Email.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = Usuario
' Password de la cuenta
Obj_Email.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Password
' Indica si se usa SSL para el envío. En el caso de Gmail requiere que esté en True
Obj_Email.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = Usar_SSL
End If
reinaldocrespo wrote:There are a few threads on the xharbour forum explaining how to build the .libs and where to download the .dlls from.
A simpler way to test if you have the open ssl libs linked, is trying to http to an https address. Once everything is in place, you can use xharbour's native emailing funcs.
Function CDOSendMail( aTabMail )
Local oEmailCfg,oEmailMsg
/* Tabmail
01 = MAILSERVER // A correct mail server address
02 = MAILFROM // A valid originator of the message
03 = MAILTO // Who it is being sent to
04 = SUBJECT // The subect
05 = BODY // The body in text format
06 = ATTACHMENT // Attachment(s)
07 = BCC // Usually NIL NOT USED
08 = LAUTHORIZATION // T or F logical for authentication
09 = USERID pour MAILSERVER // The mail server Username
10 = PW pour MAILSERVER // The mail server password
11 = Mail port defaut = 25 // The port, default is 25, set to 465 for SSL
12 = Mail HTML page // An HTML page, usually not used
13 = ssl authentification // T or F logical for SSL
14 = Mail sender // Mail sender name NOT USED
15 = Organisation sender // Organization sender NOT USED
16 = Host // Host if needed NOT USED
*/
TRY
oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT oEmailCfg:Fields
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := TRIM( aTabMail[01] ) //"mail.xxxxxxxx.com"
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := aTabMail[11] // 25
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := 2 // Remote SMTP = 2, local = 1
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := aTabMail[08] // .T.
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := aTabMail[13]
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := TRIM( aTabMail[09] ) // "xxanser@xxxxxxxx.com"
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := TRIM( aTabMail[10] ) // "xxxxxx"
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 30
:Update()
END WITH
CATCH oError
MsgInfo( "Could not create message configuration" + ";" + ;
"Error: " + TRANSFORM(oError:GenCode, NIL) + ";" + ;
"SubC: " + TRANSFORM(oError:SubCode, NIL) + ";" + ;
"OSCode: " + TRANSFORM(oError:OsCode, NIL) + ";" + ;
"SubSystem: " + TRANSFORM(oError:SubSystem, NIL) + ";" + ;
"Message: " + oError:Description )
Return .F.
END
oError:=NIL
TRY
oEmailMsg := CREATEOBJECT ( "CDO.Message" )
WITH OBJECT oEmailMsg
:Configuration = oEmailCfg
:From = aTabMail[02] //chr(34)+" Anser K.K. "+chr(34)+ "<anser@xxxxxxxx.com>" // This will be displayed in the From (The email id does not appear)
:To = TRIM( aTabMail[03] ) // "xxanserkk@xxxxx.com" // <----- Place the TO email address
:Subject = aTabMail[04] // "This is a Tst message"
:MDNRequested = .T.
:TextBody = TRIM( aTabMail[05] )
IF LEN( aTabMail[06] ) > 0
For nEle := 1 To Len( aTabMail[06] )
:AddAttachment( ALLTRIM(aTabMail[06][nEle] )) // := AllTrim( aAttach[ nEle ] )
Next
ENDIF
END WITH
oEmailMsg:Send( )
CATCH oError
MsgInfo( "Could not send message" + ";" + CRLF+ ;
"Error: " + TRANSFORM(oError:GenCode, NIL) + ";" + CRLF+;
"SubC: " + TRANSFORM(oError:SubCode, NIL) + ";" + CRLF+ ;
"OSCode: " + TRANSFORM(oError:OsCode, NIL) + ";" + CRLF +;
"SubSystem: " + TRANSFORM(oError:SubSystem, NIL) + ";" +CRLF+ ;
"Message: " + oError:Description )
Return .F.
END
Return( .t. )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 45 guests