JIMSMITH 0 Posted Sunday at 06:02 AM Has anybody been able to send email from Delphi using oauth2. Every example that I have seen includes SMTP.UseTLS := utUseExplicitTLS; and SMTP.AuthType := satOAuth2; which appear undefined in my version 11 or 10.x? I am starting from scratch as Google tends to change access requirements to send email. Share this post Link to post
DelphiUdIT 154 Posted Sunday at 08:25 AM (edited) With Indy is a little bit complex, you must install the github version and a branch "ssl-oauth". You must delete the original Indy shipped. But now some works were done and I don't know how is the status of Indy repository and relative branch. Alternative the is a thirdy tool not free (based on Indy): https://www.esegece.com/ You can try also ICS that is free, but I don't know if they have implemented Oauth protocol: https://wiki.overbyte.eu/wiki/index.php/ICS_Download Bye Edited Sunday at 08:28 AM by DelphiUdIT Share this post Link to post
DelphiUdIT 154 Posted Sunday at 10:37 AM There is also another resource on GitHub (in some topics of this forum there are some references about that): https://github.com/geoffsmith82/GmailAuthSMTP Share this post Link to post
gkobler 37 Posted Sunday at 04:02 PM 7 hours ago, DelphiUdIT said: You can try also ICS that is free, but I don't know if they have implemented Oauth protocol: https://wiki.overbyte.eu/wiki/index.php/FAQ_ICS_Email_and_OAuth2 Share this post Link to post
Remy Lebeau 1366 Posted Sunday at 05:25 PM (edited) 14 hours ago, JIMSMITH said: Has anybody been able to send email from Delphi using oauth2. Yes. 14 hours ago, JIMSMITH said: Every example that I have seen includes SMTP.UseTLS := utUseExplicitTLS; and SMTP.AuthType := satOAuth2; which appear undefined in my version 11 or 10.x? There has never been an satOAuth2 option for the AuthType property. The correct option is satSASL instead. And then you can add a suitable TIdSASL-derived component to the TIdSMTP.SASLMechanisms collection. But Indy's master code does not have a SASL component for OAuth yet... 12 hours ago, DelphiUdIT said: With Indy is a little bit complex, you must install the github version and a branch "ssl-oauth". You must delete the original Indy shipped. But now some works were done and I don't know how is the status of Indy repository and relative branch. The status of that branch has not changed, I still need to merge it into the master branch. It is on my TODO list. In the meantime, it is possible to use the TIdSMTP.SendCmd() method to manually send the relevant XOATH2 command per Gmail's documentation (https://developers.google.com/gmail/imap/xoauth2-protocol), eg: var creds: string; creds := Format('user=%s'#1'auth=Bearer %s'#1#1, [Username, Token]); IdSMTP1.SendCmd('AUTH XOATH2 ' + TIdEncoderMIME.EncodeString(creds), ['235']); // Update the DidAuthenticate property so Send() won't try to authenticate again... IdSMTP1.AuthType := satNone; IdSMTP1.Authenticate; Alternatively, you can use the sample code from this repo: https://github.com/geoffsmith82/GmailAuthSMTP/ Edited Sunday at 08:48 PM by Remy Lebeau Share this post Link to post
JIMSMITH 0 Posted yesterday at 02:02 AM (edited) 8 hours ago, Remy Lebeau said: Yes. There has never been an satOAuth2 option for the AuthType property. The correct option is satSASL instead. And then you can add a suitable TIdSASL-derived component to the TIdSMTP.SASLMechanisms collection. But Indy's master code does not have a SASL component for OAuth yet... The status of that branch has not changed, I still need to merge it into the master branch. It is on my TODO list. In the meantime, it is possible to use the TIdSMTP.SendCmd() method to manually send the relevant XOATH2 command per Gmail's documentation (https://developers.google.com/gmail/imap/xoauth2-protocol), eg: var creds: string; creds := Format('user=%s'#1'auth=Bearer %s'#1#1, [Username, Token]); IdSMTP1.SendCmd('AUTH XOATH2 ' + TIdEncoderMIME.EncodeString(creds), ['235']); // Update the DidAuthenticate property so Send() won't try to authenticate again... IdSMTP1.AuthType := satNone; IdSMTP1.Authenticate; Alternatively, you can use the sample code from this repo: https://github.com/geoffsmith82/GmailAuthSMTP/ Thanks for responding to my message. The code that you shared above with creds and ISMTP1, which full example does that get injected into? Thanks for responding to my post. Can you advise which example code should I place the creds and IdSMTP1 code into. FYI: The geoffsmith sample project prompts for user authentication. I can have that as this will execute as a back end process and not be visible to the ui. I just need to send an email Edited yesterday at 02:25 AM by JIMSMITH missing Share this post Link to post
Remy Lebeau 1366 Posted yesterday at 05:51 AM 12 hours ago, Remy Lebeau said: The status of that branch has not changed, I still need to merge it into the master branch. It is on my TODO list. I have since merged the sasl-oauth branch into the master code earlier today. 1 Share this post Link to post
Remy Lebeau 1366 Posted yesterday at 05:54 AM 3 hours ago, JIMSMITH said: Thanks for responding to my post. Can you advise which example code should I place the creds and IdSMTP1 code into. FYI: The geoffsmith sample project prompts for user authentication. I can have that as this will execute as a back end process and not be visible to the ui. I just need to send an email It doesn't matter if the username and token come from a UI or a database or a config file or an automated process. It's all the same when it gets down to the SMTP level. Share this post Link to post
DelphiUdIT 154 Posted 13 hours ago 13 hours ago, Remy Lebeau said: I have since merged the sasl-oauth branch into the master code earlier today. I install the new Indy from github and the old PR299 (with the same changes like always to maintain compatibility with Embarcadero environment and third parties) and all is working with RAD 12.2 Patch 1. I tried with the SSL DLL 3.1.5 for HTTPS and e-mail (not Oauth) and is working. Also the new OAuths in the components palette. I didn't try them. The new (but it worse) is that "LivePreview" should not be installed. It generate AV in the IDE on startup and shutdown. Share this post Link to post