Page 1 of 2

Send EMail Within FW Appplication (RESOLVED)

PostPosted: Tue Jun 08, 2021 11:11 am
by RiazKhan
Hi All,

A client has asked to send a payslip via email to all employees from the payroll module. This requires sending the email from Gmail to Gmail users. All employees have an email address in their profile, get tagged for an email.

I have tried some examples from this forum and also tested testsmtp.prg. But with no success.

I have provided sendmail() with from/to/subject/message/password/attachment..all the parameters. No success..

Is there a test prg available to share, for me to get the concept clear?

Thnx in advance...

Re: Send EMail Within FW Appplication....

PostPosted: Tue Jun 08, 2021 12:43 pm
by Rick Lipkin
RiazKhan

Don't forget .. you will need to "allow less secure apps" to be turned on for the sending gmail account ..

Rick Lipkin

Re: Send EMail Within FW Appplication....

PostPosted: Tue Jun 08, 2021 3:02 pm
by karinha
Disable 2-step verification
Open your Google Account.
In the "Security" section, select 2-Step Verification. You may need to login.
Select Disable.
A pop-up window will appear to confirm that you want to disable 2-step verification. Select Disable.

Regards.

Re: Send EMail Within FW Appplication....

PostPosted: Tue Jun 08, 2021 4:17 pm
by RiazKhan
Yes, Thank you for your prompt reply..

I already have set these as in my Gmail account....

Allow Less Secure Apps - is ON
2-step verification - DISABLED

I am passing all parameters to sendmail()

SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, aAttach, cSender, cUser, cPassword, aCc, lHtml, cPort,lNotification , lSSL )

This is the return message : "Unsent message check windows live mail"

LOCAL cFrom := "amriazkhan@gmail.com"
LOCAL cServer := "smtp.gmail.com"
LOCAL cTo := "TO Address"
LOCAL cSubject := "Test message"
LOCAL cMessage := "This is a test message."
LOCAL cSender := "amriazkhan@gmail.com"
LOCAL cUser := "amriazkhan@gmail.com"
LOCAL cPassword := "xxxxxxxx"
LOCAL aAttach := {}
LOCAL aCc := "" //???
LOCAL lHtml := .F.
LOCAL lSSL := .F.
LOCAL cPort := "465"
LOCAL lNotification := .F.
LOCAL lRet := .F.

Any parameter missing..??

Re: Send EMail Within FW Appplication....

PostPosted: Tue Jun 08, 2021 4:28 pm
by karinha
Use google Translator, please:

https://i.imgur.com/S5rFI1S.png

Image

Regards, saludos.

Re: Send EMail Within FW Appplication....

PostPosted: Tue Jun 08, 2021 4:46 pm
by karinha
Code: Select all  Expand view

{"@pop.gmail.com",         "smtp.gmail.com",          465, .T. },;


LOCAL cFrom := "amriazkhan@gmail.com"
LOCAL cServer := "smtp.gmail.com"
LOCAL cTo := "TO Address"
LOCAL cSubject := "Test message"
LOCAL cMessage := "This is a test message."
LOCAL cSender := "amriazkhan@gmail.com"
LOCAL cUser := "amriazkhan@gmail.com"
LOCAL cPassword := "xxxxxxxx"
LOCAL aAttach := {}
LOCAL aCc := "" //???
LOCAL lHtml := .F.
LOCAL lSSL :=   .T. // .F.
LOCAL cPort := "465"
LOCAL lNotification := .F.
LOCAL lRet := .F.
 


Regards, saludos.

Re: Send EMail Within FW Appplication....

PostPosted: Tue Jun 08, 2021 5:48 pm
by RiazKhan
Still no luck with sending email via gmail.com...

Re: Send EMail Within FW Appplication....

PostPosted: Tue Jun 08, 2021 6:00 pm
by karinha
Try this:

https://accounts.google.com/b/0/DisplayUnlockCaptcha

And

Port: 587 or 995

Regards.

Re: Send EMail Within FW Appplication....

PostPosted: Tue Jun 08, 2021 6:12 pm
by karinha
Check if gmail has "temporarily blocked" account access.

From time to time, or when you create a new account and try to use an external program to transmit email, gmail blocks access for "suspected misuse" and asks for account confirmation.

Generally, to resolve this, go through your browser, log out of your account and try logging in again.

Gmail will ask for confirmation and send a code to your cell phone.

Do the procedure and gmail will grant access again.

It happened a few times with some of our clients, and after I confirmed the account, the program started sending again normally.

Regards.

Re: Send EMail Within FW Appplication....

PostPosted: Tue Jun 08, 2021 7:32 pm
by RiazKhan
Thanks ....for your support.

I have tried many ways...to send an email from my application....but it does not respond...

Part of the function is listed below...from this forum..

******************************************************************************************************
STATIC FUNCTION SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, aAttach, cSender, cUser, cPassword, aCc, lHtml, cPort, lNotification, lSSL )

LOCAL lOk := .F.

LOCAL oCfg, oMsg

LOCAL cCc := ""

LOCAL i

DEFAULT lHtml := "<html" $ LOWER( cMessage )
DEFAULT lNotification := .F.
DEFAULT lSSL := .F.

TRY
oCfg = CREATEOBJECT( "CDO.Configuration" )

oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value = cServer

IF !EMPTY( cPort )
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := VAL( cPort )
ENDIF

oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value = 2
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value = .F.

IF !EMPTY( cUser ) .AND. !EMPTY( cPassword )
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value = .T.
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value = cUser
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := cPassword
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value = lSSL
ENDIF

oCfg:Update()

oMsg = CREATEOBJECT( "CDO.Message" )

oMsg:Configuration = oCfg

IF !EMPTY( cSender ) THEN cFrom = ["] + cSender + ["] + " <" + cFrom + ">"

oMsg:From = cFrom
oMsg:To = cTo
oMsg:Subject = cSubject

IF !EMPTY( aCc )
FOR i = 1 TO LEN( aCc )
IF i > 1 THEN cCc += ";"
cCc += aCc[ i ]
NEXT

oMsg:CC = cCc
ENDIF

IF !lHtml
oMsg:TextBody = cMessage
ELSE
oMsg:HTMLBody = cMessage
ENDIF

IF !EMPTY( aAttach )
FOR i = 1 TO LEN( aAttach )
oMsg:AddAttachment( aAttach[ i ] )
NEXT
ENDIF

IF lNotification
oMsg:Fields:Item( "urn:schemas:mailheader:disposition-notification-to" ):Value = cFrom
oMsg:Fields:Update()
ENDIF

oMsg:Send()

lOk = .T.
CATCH
END

RETURN lOk
***************************************************************************************

No luck....

Re: Send EMail Within FW Appplication....

PostPosted: Wed Jun 09, 2021 12:43 pm
by karinha
Mensagem enviada com sucesso. -> Message sent successfully.

https://i.imgur.com/6V830B9.png

Image

My sender is working fine. Had to turn off google security.

Allow less secure apps: ON

https://i.imgur.com/0I024bs.png

Image

Image

Regards, saludos.

Re: Send EMail Within FW Appplication....

PostPosted: Wed Jun 09, 2021 12:49 pm
by karinha
https://myaccount.google.com/security?pmr=1

https://myaccount.google.com/lesssecureapps?pli=1&rapt=AEjHL4NBKR97Jli4gceS35qOxkYX6FnEL3I6uGkA5Qg_5ftggb_siiMQ6LLQKX20I4sA4x8BkkrYirPuZrD4ssJgnjgjqz2zbw

I use the RMAIL.PRG modified by me for use in the company I work for and it works very well. If you wish, I send the link for you to download and test. Greetings.

Regards, saludos.

Re: Send EMail Within FW Appplication....

PostPosted: Wed Jun 09, 2021 2:46 pm
by RiazKhan
Thanks Karinha,

Yes, I will appreciate it very much if you can send, me the link of rmail.prg for testing purposes...
As I feel I am doing all my settings right with google security.

amriazkhan@gmail.com

Regards

Re: Send EMail Within FW Appplication....

PostPosted: Thu Jun 10, 2021 7:28 pm
by James Bott
Here is a very old message thread discussing this topic.

http://forums.fivetechsupport.com/viewtopic.php?f=3&t=15843&p=82081&hilit=gmail#p82081

Also note the info about the firewall blocking port 465.

Re: Send EMail Within FW Appplication....

PostPosted: Fri Jun 11, 2021 7:18 am
by RiazKhan
Thank You,

James & Santos..

Will check..both solutions...and will get back to you..

Kind Regards..