FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Send EMail Within FW Appplication (RESOLVED)
Posts: 99
Joined: Fri Dec 16, 2011 03:30 PM
Send EMail Within FW Appplication (RESOLVED)
Posted: 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...

FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Send EMail Within FW Appplication....
Posted: 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

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Send EMail Within FW Appplication....
Posted: Tue Jun 08, 2021 03: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
Posts: 99
Joined: Fri Dec 16, 2011 03:30 PM
Re: Send EMail Within FW Appplication....
Posted: Tue Jun 08, 2021 04: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
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Send EMail Within FW Appplication....
Posted: Tue Jun 08, 2021 04:28 PM
Use google Translator, please:

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



Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Send EMail Within FW Appplication....
Posted: Tue Jun 08, 2021 04:46 PM
Code (fw): Select all Collapse
{"@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
Posts: 99
Joined: Fri Dec 16, 2011 03:30 PM
Re: Send EMail Within FW Appplication....
Posted: Tue Jun 08, 2021 05: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
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Send EMail Within FW Appplication....
Posted: Tue Jun 08, 2021 06: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
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Send EMail Within FW Appplication....
Posted: Tue Jun 08, 2021 06: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
Posts: 99
Joined: Fri Dec 16, 2011 03:30 PM
Re: Send EMail Within FW Appplication....
Posted: Tue Jun 08, 2021 07: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
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Send EMail Within FW Appplication....
Posted: Wed Jun 09, 2021 12:43 PM
Mensagem enviada com sucesso. -> Message sent successfully.

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



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

Allow less secure apps: ON

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





Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Send EMail Within FW Appplication....
Posted: 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
Posts: 99
Joined: Fri Dec 16, 2011 03:30 PM
Re: Send EMail Within FW Appplication....
Posted: Wed Jun 09, 2021 02: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Send EMail Within FW Appplication....
Posted: Thu Jun 10, 2021 07: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
Posts: 99
Joined: Fri Dec 16, 2011 03:30 PM
Re: Send EMail Within FW Appplication....
Posted: Fri Jun 11, 2021 07: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