-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] Support OAuth2 for gmail properly #35528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If this can be implemented easily without external dependency, I think this is a good idea. If the only practical way to implement this feature is to depend on |
+1 |
I agree with @stof. Anyone wanted to have a look? |
Some handy notes that may help based on my experience using Gmail and OAUTH, and to possibly open up discussion on which Gmail transport to support (SMTP or Gmail API or both). Scopes using
Note: It's not a requirement but Google prefers you to use minimal scope access for the action you need. This is more an integration thing and outside the scope of this. Cleanup
Personally I think it should be sending using OAuth 2.0 via SMTP or Gmail API functionality only and the OAuth token generation/refresh/storage should be for the user to implement. |
What finally happened to this? I can't find a way to send emails to gmail with oauth. |
Thank you for this suggestion. |
Friendly ping? Should this still be open? I will close if I don't hear anything. |
This can work with SMTP as well, it doesn't necessarily need the Google (or Microsoft, which will also require XOAUTH2 eventually) client library. Swiftmailer does it here: https://github.com/swiftmailer/swiftmailer/blob/5.x/lib/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php In terms of using an SMTP transport, it's essentially just a different way to build up the authentication command: $email = 'foo@example.com';
$token = 'asdfxxx........';
$authString = base64_encode("user=$email\1auth=Bearer $token\1\1");
$connection->executeCommand("AUTH XOAUTH2 $authString"); |
To me, it might make sense to support |
Gmail justy only supports oauth It would be great to have native oauth libraries. |
Thank you for this suggestion. |
Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3 |
This has been re-requested as a duplicate a few days ago at #46033 |
I'd like to see this implemented |
To see this implemented, someone has to implement it. |
@derrabus: clearly. I was replying to #35528 (comment). Anyway, I'll give it a try. I never got in this code so I'm not sure I'll be able to pull it off but still, I'll try my best. |
I hope someone will implement this, the support for "less secure application" for connecting to Gmail dropped yesterday :( Thanks ! |
Well, "hoping" does not help finding someone to do the work... |
For the short term a working solution is to use the App Passwords. This requires you to enable the Two-Factor Authentication but then it should work with the same configuration as before, just with the App password instead of the account password. You can find more info here: https://wpmailsmtp.com/gmail-less-secure-apps/ |
Hi everybody! I would like to add some "thoughts" to this discussion because can help us. Looking information about XOAUTH2 Gmail protocol I ended in this page https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2. After looking all the steps of how PHPMailer resolve this authentication, maybe it's possible to use a similar workarround with If Symfony mailer transport it's mandatory to be not coupled to With this token fetched maybe can be accepted to add a XOAuth2Authenticator class in |
@davidromani For reference, we already have such an authenticator for SMTP here: src/Symfony/Component/Mailer/Transport/Smtp/Auth/XOAuth2Authenticator.php |
@fabpot thanks for your hint! Is there any example or documentation related on how to use this authentication method with |
I have written for me a custom GmailOAuthTransportFactory which extends AbstractTransportFactory and an GmailOAuthSmtpTransport which extends SmtpTransport but i already use the google apiclient in my app and therefore already have the token. Then you can use this GmailOAuthTransportFactory via config in your services.yaml:
The authentication is pretty much the same as @fabpot mentioned in the XOAuth2Authenticator class:
@fabpot: Any idea, what helps the project to provide a solution for google mail without adding dependencies? |
Just wanted to voice my support for this work. Wish I could help with the coding, but I'm out of my depth for that. I wrote some Google authentication and Gmail API custom code in a Mediawiki extension a year ago roughly, but I'm still too new to Symfony to be able to carry that over somehow. |
oauth2 authentication for gmail is a must since google disable the less secure app feature since 30/05/2022 therefore it is not possible anymore to send email via "classic" user/password Actually gmail transport is unusable |
@bobonov adding more comments saying this is wanted does not help. What we need is someone working on an implementation. |
@stof I didn't just write I want it (actually, I'm doing a new implementation and I just dropped the hypothesis of using gmail smtp). I simply wrote that since 30/05/2022 this driver without oauth2 is dead code. @ThomasTr "...provide a solution for google mail without adding dependencies?" I would love to help but my experience with aouth2 client is just to use client that other have wrote. In a project a while ago, I was sending email via gmail using oauth2.
Maybe a similar approach can be used. |
I'm going to close here as there is a solution that is simple enough: using app passwords (as mentioned in one comment above: #35528 (comment)). It needs 2FA to be enabled on your account though (but I suppose everybody should do it anyway). I've just tested it and it works fine. |
Currently App Password disabled on 30.09.2024 so gmail will no longer work. |
@boonkerz the article you link does not talk about disabling app passwords. It actually even mentions them as one of the alternatives. |
@stof i think this is the correct article form google https://support.google.com/a/answer/14114704?hl=en&fl=1&sjid=14336799637165458190-NA |
@EvilKarter here is a quote from the introduction of that post:
App passwords are not removed by Google. |
Unfortunately, Google has turned off App Passwords today: |
Nope, app passwords still working. Using it at the moment via imapsync to migrate my google workspace accounts to selfhosted mailserver. |
As of February 15, 2021, sending emails with Google G Suite accounts will only be possible with apps that use OAuth.
OAuth2 Authentication is already implemented via the XOAuth2Authenticator. But it uses the password as acces_token. Since its validity is limited to one hour, this is not a practicable way.
At the moment i have written my own custom transport (gmail+oauth), since i have already included google/apiclient and oauth handling/storing in my app.
I think it makes sense to implement oauth token - handling / - renewing / - storage in symfony/google-mailer, otherwise it will make it obsolete after February 15, 2021.
What do you think. Maybe i could help out with this.
The text was updated successfully, but these errors were encountered: