Send EMail Within FW Appplication (RESOLVED)

Re: Send EMail Within FW Appplication....

Postby cmsoft » Fri Jun 11, 2021 1:52 pm

Hello RiazKhan,
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)
User avatar
cmsoft
 
Posts: 1262
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Send EMail Within FW Appplication....

Postby Massimo Linossi » Sat Jun 12, 2021 8:12 am

User avatar
Massimo Linossi
 
Posts: 495
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: Send EMail Within FW Appplication (RESOLVED)

Postby RiazKhan » Sat Jun 12, 2021 6:57 pm

Dear All,

The sample provided by Mr.Cesar Gomez, was just perfect. Was exactly what I wanted, after a few modifications as per my needs. It worked perfectly. Thank You Cesar Gomez.

Thank you Massimo Linossi, but the site you provided MialBee, does not have a trial version and is not license-free.

Thank you all, for your support and feed back.

Kind regards..
FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
User avatar
RiazKhan
 
Posts: 99
Joined: Fri Dec 16, 2011 3:30 pm
Location: Pakistan

Re: Send EMail Within FW Appplication (RESOLVED)

Postby cmsoft » Sat Jun 12, 2021 9:58 pm

I am very glad that it has been useful to you!
User avatar
cmsoft
 
Posts: 1262
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], TimStone and 51 guests