1. Tracy Lamb
  2. PowerBuilder
  3. Friday, 8 December 2023 23:55 PM UTC

Hi all,

Using PB2022 R2.  Thought I'd play around with the new SMTP features.

I've got a window with a button on it.  The button just sends a test message via SMTP.  Everything is hard coded. SMTPClient.Send keeps returning an error.  Here's the code: 

Integer li_rc
SMTPClient  lnv_SmtpClient

lnv_SmtpClient = CREATE SMTPClient

//Sets the email-sender information       
lnv_SmtpClient.Host = "smtp.gmail.com"
lnv_SmtpClient.Port = 465
lnv_SmtpClient.Username = "myemail@gmail.com"
lnv_SmtpClient.password = "mypassword"
lnv_SmtpClient.EnableTLS = False

//Sets the email message
lnv_SmtpClient.Message.SetSender("myemail@gmail.com" , "My Name")
lnv_SmtpClient.Message.AddRecipient("abc.123@MyCompany.com")
lnv_SmtpClient.Message.Subject = "SMTPClient Test Message"
lnv_SmtpClient.Message.TextBody = "SMTPClient example message body"

//Sends the email
li_rc = lnv_SmtpClient.Send()

IF li_rc = 1 THEN
                Messagebox('SMTPClient','Mail sent successfully')
ELSE
                Messagebox('SMTPClient' ,'Email sending failed. Return ' + String(li_rc) + '.', StopSign!)
END IF

DESTROY lnv_SmtpClient

(Username and password changed to protect the innocent.)

When I use port 465, TLS = FALSE, I get error -14 .

When I use port 587, TLS = TRUE, I get error -12.

Any thoughts?

~~~Tracy

Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 13 December 2023 15:53 PM UTC
  2. PowerBuilder
  3. # 1
Comment
  1. Tracy Lamb
  2. Wednesday, 13 December 2023 17:54 PM UTC
I'm trying to use option 2. All my settings are correct. I keep getting an error message Error -12 -- The remote server denied the Curl login. This occurs with port 587, TLS enabled.
  1. Helpful
There are no comments made yet.
Simone Olianti Accepted Answer Pending Moderation
  1. Wednesday, 13 December 2023 15:12 PM UTC
  2. PowerBuilder
  3. # 2

probably you need the oauth2 authentication
looking at the powerbuilder help there is an example using a gmail account which refers to the "XOAuth2AccessToken property":
have to try this myself aswell but HTH

Integer li_rc
SMTPClient  lnv_SmtpClient

lnv_SmtpClient = CREATE SMTPClient

//set the email message
lnv_SmtpClient.Message.SetSender("tester001.appeon@gmail.com","Tester001")
lnv_SmtpClient.Message.AddRecipient("tester002.appeon@gmail.com")
lnv_SmtpClient.Message.Subject = "SMTPClient Test Message"
lnv_SmtpClient.Message.TextBody = "SMTPClient example message body"

//set the email account information     
lnv_SmtpClient.Host = "smtp.gmail.com"
lnv_SmtpClient.Port = 587
lnv_SmtpClient.EnableTLS = True
lnv_SmtpClient.Username = "tester001.appeon@gmail.com"

//Model Authentication.
lnv_SmtpClient.XOAuth2AccessToken = "ya29.a0AVvZVsrZY8ra_fyIw3EyVSYUQIXYbWcz4_mYqlqtxFE-4t_hzLyV_BaZbaxhM3nC10Nr5Qm6hmHPBQvd5BfaH7kXN5KxS-XR0dnV-1EHltUJmcgBSZIHbPEkR6qLf_CEaEozOESSyebgAWv5SGynKfyCzsvR6QaCgYKAeMSARASFQGbdwaIy4ayfJPAa23BKltg4-AJjg0165"

//send the email
li_rc = lnv_SmtpClient.Send()

IF li_rc = 1 THEN
 Messagebox('SMTPClient','Mail sent successfully')
ELSE
 Messagebox('SMTPClient' ,'Email sending failed. Return ' + String(li_rc) + '.', StopSign!)
END IF

DESTROY lnv_SmtpClient

//Note: For more information about how to get the Access Token, refer to the TokenRequest object.

Comment
  1. Tracy Lamb
  2. Wednesday, 13 December 2023 17:49 PM UTC
Thank you for the feedback. I don't have a gmail administrator account... that's for people who administer google email/cloud services for an organization. I'm not finding a way to generate an AccessToken for a stand-alone gmail account.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Saturday, 9 December 2023 03:18 AM UTC
  2. PowerBuilder
  3. # 3

Hi, Tracy - 

I found this relatively recent post by using the search feature in the Community Q&A:

    https://community.appeon.com/index.php/qna/q-a/send-email-in-pb-2022-r2-using-a-gmail-account

I believe this will answer your question.

Best regards, John

Comment
  1. Tracy Lamb
  2. Saturday, 9 December 2023 14:13 PM UTC
Resort to...
  1. Helpful
  1. John Fauss
  2. Saturday, 9 December 2023 21:43 PM UTC
??????

The following response in the referenced thread by the original poster seems pretty clear to me:

----------------

I did the setup necessary for google and it still didn't work.

Created an outlook account and that worked fine.

Thanks for all the ideas :-)

----------------
  1. Helpful
  1. Tracy Lamb
  2. Sunday, 10 December 2023 15:47 PM UTC
That's what I thought it said... he resorted to Outlook. I've been doing that for several years, without the new SMTP feature in PB2022. But not having any luck sending mail with the SMTPClient object to smtp.gmail.com .
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.