I have had the same problem recently.
I could solve it by adding the password for gmail applications, here is the [url]link: https://support.google.com/mail/answer/185833?hl=es-419[/url]
This is my code:
- Code: Select all Expand view
*-------------------------------------------------*
STATIC Function EnviarPorMail(cdestino)
*-------------------------------------------------*
LOCAL loCfg, loMsg, oError, isError := .F., oRep, cHtml, i, cColor
local cSMTP := "smtp.gmail.com"
Local cPuerto := 465
Local cLogin := "mimail@gmail.com"
Local cPassword := "mipassword_app"
local cRemitente:= "<Factura Electronica>"
Local cAsunto := "Envio de Factura electronica"
Local cMensaje := "Adjuntamos la factura electronica"+CRLF+CRLF+CRLF
local cSSL := .T., cAuth := .T.
local cFichero := nil
// Control autentificación via SSL
IF alltrim( cSMTP ) = "smtp.live.com"
cSSL := .T.
ELSEIF alltrim( cSMTP ) = "smtp.gmail.com"
cSSL := .T.
ENDIF
// Armado del HTML
cHTML :=''
cHTML +='<!--' + CHR(10)+CHR(13)
cHTML +=' Document : Index HTML' + CHR(10)+CHR(13)
cHTML +=' Created on : 11/03/2013, 12:35:37 PM' + CHR(10)+CHR(13)
cHTML +=' Author : Yo' + CHR(10)+CHR(13)
cHTML +=' Description: http://www.sigloxxicampana.edu.ar' + CHR(10)+CHR(13)
cHTML +='-->' + CHR(10)+CHR(13)
cHTML +='' + CHR(10)+CHR(13)
cHTML +='<html>' + CHR(10)+CHR(13)
cHTML +=' <head>' + CHR(10)+CHR(13)
cHTML +=' <title>Factura electronica</title>' + CHR(10)+CHR(13)
cHTML +=' </head>' + CHR(10)+CHR(13)
cHTML +=' ' + CHR(10)+CHR(13)
cHTML +=' <body>' + CHR(10)+CHR(13)
cHtml += '<img src="https://www.fivetechsoft.com/spanish/images/1page-img1.jpg" alt="Logo" width="100">' + CHR(10)+CHR(13)
cHtml += '<p style="font-family: sans-serif; font-size: 16px; text-align: justify;">' + CHR(10)+CHR(13)
cHtml += 'Adjuntamos al presente mail la factura del mes en curso'
cHTML +=' </body>' + CHR(10)+CHR(13)
cHTML +='</html>' + CHR(10)+CHR(13)
// Internet
loCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT loCfg:Fields
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := cSMTP // "smtp.gmail.com"
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := cPuerto //465
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := 2
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := cAuth //.T.
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := cSSL // .T.
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := cLogin //tu cuenta de correo de salida
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := cPassword //"" //con tu clave gmail. en este caso
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 30
:Update()
END WITH
loMsg := CREATEOBJECT ( "CDO.Message" )
WITH OBJECT loMsg
:Configuration = loCfg
:From = cLogin //cRemitente
:To = cDestino
:Subject = cAsunto
:MDNRequested = .f.
:HTMLBody = cHtml
:AddAttachment(hb_CurDrive()+":\"+CurDir()+"\FACTURA.PDF")
:Send()
END WITH
IF isError = .F.
MsgWait( "Mensaje enviado correctamente a " + cDestino, " A V I S O ",0.2 )
ELSE
MsgStop("ERROR: Se ha producido un error al enviar un mensaje al buzon "+cDestino+CRLF+CRLF+"Descripción del Error: "+oError:Description, " E R R O R ")
ENDIF
return nil
I hope it is useful for you
(Sorry for my English, it's the translator)