Send EMail Within FW Appplication (RESOLVED)

Send EMail Within FW Appplication (RESOLVED)

Postby RiazKhan » Tue Jun 08, 2021 11:11 am

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...
Last edited by RiazKhan on Sat Jun 12, 2021 6:59 pm, edited 1 time in total.
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....

Postby Rick Lipkin » Tue Jun 08, 2021 12:43 pm

RiazKhan

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

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Send EMail Within FW Appplication....

Postby karinha » Tue Jun 08, 2021 3:02 pm

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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send EMail Within FW Appplication....

Postby RiazKhan » Tue Jun 08, 2021 4:17 pm

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..??
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....

Postby karinha » Tue Jun 08, 2021 4:28 pm

Use google Translator, please:

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

Image

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send EMail Within FW Appplication....

Postby karinha » Tue Jun 08, 2021 4:46 pm

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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send EMail Within FW Appplication....

Postby RiazKhan » Tue Jun 08, 2021 5:48 pm

Still no luck with sending email via gmail.com...
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....

Postby karinha » Tue Jun 08, 2021 6:00 pm

Try this:

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

And

Port: 587 or 995

Regards.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send EMail Within FW Appplication....

Postby karinha » Tue Jun 08, 2021 6:12 pm

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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send EMail Within FW Appplication....

Postby RiazKhan » Tue Jun 08, 2021 7:32 pm

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....
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....

Postby karinha » Wed Jun 09, 2021 12:43 pm

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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send EMail Within FW Appplication....

Postby karinha » Wed Jun 09, 2021 12:49 pm

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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Send EMail Within FW Appplication....

Postby RiazKhan » Wed Jun 09, 2021 2:46 pm

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
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....

Postby James Bott » Thu Jun 10, 2021 7:28 pm

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.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Send EMail Within FW Appplication....

Postby RiazKhan » Fri Jun 11, 2021 7:18 am

Thank You,

James & Santos..

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

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 114 guests