-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
PHPMailer gmail_xoauth.phps example from github #677
Comments
OK, a little progress, but can anyone advise where to go from here ??? I executed get_auth_token.php again, received a new Refresh Token, which I immediately entered into https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx the return is So ... where am I going wrong. I'm a novice in this area and any suggestions are appreciated. |
I'm not sure what's wrong there, it looks like you're doing it all right. You may or may not be glad to know that this is all changing... If you look in the xoauth branch there is a major refactor underway that should make using xoauth2 a bit more transparent, though it's not quite there yet. I quite agree that OAuth is horribly confusing to work with! BTW if you find differences in the wiki, it's publicly editable, so please do update it so that others can benefit. |
Hello Synchro ! Another minor step forward. I have managed to get a valid access_token. I tried substituting "$mail->oauthAccessToken =" instead of "$mail->oauthRefreshToken =" but end up with Fatal error: Uncaught exception 'League\OAuth2\Client\Provider\Exception\IdentityProviderException' I'm a novice at OAuth. Can you tell me why the code is using a refresh token instead of the access token ? Also, when I try "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=xxx" I get a valid response back. If I use the refresh token instead, the response is "error": "invalid_token". Since the access token for GMail expires in 1 hour I wonder why the code does not include logic to refresh the access token after some period of time ? Again, I am wondering why a refresh token is used in the code instead of the access token ??? I keep looping back in my mind to "SMTP ERROR: AUTH command failed: 334" and why this might be happening. |
@renardrouge I see that you are obtaining a Client Id for Web Server app. Can you please try getting the credentials for a Client Side using Javascript option for Calling from where option. Even though we run PHPMailer from a Web Server the working of a google Webserver App is completely different from our scenario. We make PHPMailer work as a client side app in order to get the refresh token. We store this refresh token and use it for subsequent calls and send mails. |
@renardrouge I think the above way should work if everything else is fine at your ebd. Or if you still have issues you can simply try using the code in Xoauth branch to double check things |
Hello sherryl4george ! Can you provide more detail please. I am new at this OAuth stuff. I am using PHP not Javascript, so I do not understand why or how I should be requesting a Javascript option. Can you be more specific in how to "use the code in Xoauth branch to double check things" ? |
Thanks ! Can you explain why a refresh token is used in the gmail_xoauth.php example rather than an access token ? I will try your credential setup suggestion to see if that makes any difference. |
Typically Access tokens are short lived unlike Refresh tokens which are If we use a Access token directly without a Refresh token we don't have a On Thursday, April 7, 2016, renardrouge [email protected] wrote:
Regards, |
OK, I think I understand. So this means that an access token is really aquired behind the scenes ??? Is there a way I can find the current access code in use by the gmail_xoauth.php example ??? |
Yes. You are absolutely correct. To see what the current access token, and if you are using the Master branch go to the file |
Oooops ! I see I made an error in that setup. I missed localhost. I will redo. |
Yes this is fine. You can go ahead and create the credentials. The On Thursday, April 7, 2016, renardrouge [email protected] wrote:
Regards, |
Hello Synchro ! Looking at the new gmail_xoauth.php code. Isn't it missing "require '../PHPMailerAutoload.php';" ??? |
@renardrouge no - in the new version composer takes care of loading both PHPMailer and dependencies. Much neater! |
OK, thanks. I am just about to try new version. Cross my fingers !!! |
with the new code I get When I do the require on ../PHPMailerAutoload.php I get "Fatal error: Namespace declaration statement has to be the very first statement in the script in C:\xampp\htdocs\phpmailer2\gmail_xoauth_v2.php on line 7" Help !!! |
Hello Syncro ! I am stuck. I uninstalled and reinstalled the latest composer. Composer version 1.0-dev (40c14709f79f9d7ea35ac969cfbd7f41beb525bb) 2016-04-05 I then executed a "composer update". I tried the new gmail_xoauth.php code again, with the single require for autoload.php and I get "Fatal error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in C:\xampp\htdocs\phpmailer2\gmail_xoauth_v2.php on line 18" Suggestions ??? I am running on a Windows laptop. |
Can you please run me through how you go about from the first step. Just to On Thursday, April 7, 2016, renardrouge [email protected] wrote:
Regards, |
Hi sherryl4george ! Well, I found I had to dig into composer syntax again. The ReadME says to add "phpmailer/phpmailer": "~5.4" to the .json file, but that did not work. I finally got version 5.4 to install with a "composer update" and the following .json { I then ran gmail_xoauth again and I am stuck at Fatal error: Call to undefined method PHPMailer\PHPMailer\PHPMailer::setOAuth() in C:\xampp\htdocs\phpmailer2\gmail_xoauth_v2.php on line 56 line 56 starts with Suggestions ??? Looking at this further, perhaps I do not have the correct levels of the "league/" components ? |
I feel you have a lot of stuff going into the composer.json file. My version would just have and addition of |
OK, here is my composer.json now composer update -- no-dev says "Package "no-dev" listed for update is not installed. Ignoring. I still get the same error "Fatal error: Call to undefined method PHPMailer\PHPMailer\PHPMailer::setOAuth() in C:\xampp\htdocs\phpmailer2\gmail_xoauth_v2.php on line 56" |
I have been searching the /vendor libraries for setOauth() and have not been successful. Where should it be located ??? |
So ... I deleted my /vendor library and ran "composer update" with this .json The result is
Same failure on gmail_xoauth.php. So ... the problem seems to be the absence of setOauth(). Would you mind checking the library list above with your install ? Have you been able to run the new gmail_xoauth successfully ? |
Hi Sherryl4george ! 6 hours ago, you stated "If in Xoauth branch the same can be found in src\OAuth.php around line 100. The function getToken just above this does all the work to get access token from refresh token." I can not find a src\OAuth.php file anywhere under the \vendor directory so I am obviously not using the same source libraries as you are. The closest I can find is PHPMailerOAuth.php So it seems I am stuck until someone can tell me how to properly build the correct library structure. |
OK, I am a little slow at figuring out what is going on. I finally found the "missing" files at https://github.com/PHPMailer/PHPMailer/tree/xoauth . My question is "How do I properly build the library ?" Can I do this with composer ? How ? If not, do I build it manually ? |
Hope you did a Clone of xoauth branch and you have the correct files. Now go to composer.json and add |
Hi ! See my comments 1 hour ago. I have already run the composer update with |
Good day members ! I don't know where to go from here. Any suggestions that might aid in narrowing down why Google refuses to authenticate ??? I wonder if one of you could try the latest gmail_xoauth.php code yourself and report on successful execution ??? SERVER -> CLIENT: 220 smtp.gmail.com ESMTP cl4sm4182496igb.4 - gsmtp |
Can you please send me the file you are running to me. I will check and let On Friday, April 8, 2016, renardrouge [email protected] wrote:
Regards, |
Hi Sherryl ! It works !!! It works !!! As I was cleaning up the client secret and id for dispatch I noticed that I had neglected to change the Thank you for getting me to this point. Can you explain the technical details as to why it only works at the root level ? I do not understand why the Javascript declaration of https://localhost was necessary or how it comes into play in the interaction. |
Here is a puzzle in the new get_oauth_token.php code. I had to use $redirectUri = 'https://localhost/get_oauth_token.php'; Examining the code yields these results. redirectUri = https://
|
My solution:
|
A better solution:
|
That's just what I was thinking - it will be down to the operator precedence of |
Hi Synchro ! |
It's not required to be anywhere - it can be any URL. That line in the token script attempts to generate a URL that points back at itself, wherever you put it. For the token issuing mechanism to work it needs a URL to send the result back to, so rather than making you set one, we attempt to generate one that should work in many cases. If it doesn't work, you can just set it manually to whatever you need. Generally you will only need to do this once - once you have the refresh token, you don't need to go through the process again, and you can use that key as many times as you like behind the scenes for actually sending your messages. This is why the token script is pretty basic - only developers will need to use it; it's unlikely that you'd want it to be user-facing. It's not really anything to do with javascript - it's just a URL that google's scripts will call when they issue the token. |
Now I am puzzled. I think it was sherryl4george's advice to set up the Javascript uri to point at https://localhost along with moving all of the operational code to the localhost root that got me going. |
Yes you can. You can move it to anywhere now. I asked to move it to the root just to make sure that we don't miss anything while creating the refresh token. You can move it to any level now but may have to set the proper redericturi once if at all you have to generate the refresh token. Sorry for the confusion that I made. |
Really appreciate your patience to sit through and sort out things. Hope now it works like a charm. |
OK, thanks for the response. I am still puzzled as to why it suddenly executed at the root level though. |
??? in the last version, this code executed properly.
Now I get "Notice: Undefined property: PHPMailer\PHPMailer\PHPMailer::$Version in C:\xampp\htdocs2\phpmailer_version.php on line 17" Where do I look to find valid properties in the new code ??? |
Thank you all ! I have moved back to directory /phpmailer under the root directory with complete success. My only outstanding item now is how to fix the code below that executed successfully in the last previous version of PHPMailer.
Now I get "Notice: Undefined property: PHPMailer\PHPMailer\PHPMailer::$Version in C:\xampp\htdocs1\phpmailer\phpmailer_version.php on line 17" |
The |
Thank you for the VERSION solution !!! I am now checking for documentation. The best I have found so far is at http:https://phpmailer.github.io/PHPMailer/ ... but it does not include VERSION as a constant. I see generatedocs.sh can generate documentation, but it appears to not be Windows compatible ??? For example, my command line does not understand the "rm" command. If it did work it appears that I need the phpdoc package too ??? Is there any hope for me to be able to generate this documentation on a Windows 10 platform ??? If so, any references for building on Windows 10 ??? |
Well ... I have phpDocumentor running on a sample.php file and the output looks good. I had a warning message during the run, so I will try to fix that. Unable to find the The question is ... if I manage to get this running, will I be able to get documentation relative to the latest development code that I am currently running on ??? |
OK, GraphViz installed and sample runs clean. |
OK, I have answered my own question. I have phpDocumentor producing documentation for PHPMailer.php and VERSION shows under Constants. That's it for tonight !!! |
I have upgraded to the latest xampp with PHP 7.0 and have encountered the following error with gmail_oauth.php Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate I can make this go away by patching the Client.php module of guzzle under /vendors in the private function configureDefaults from 'verify' => true, to 'verify' => false, I know it is not proper protocol to modify modules under /vendor, but alas, my PHP skills are lacking. I have tried for the last day to set this from gmail_oauth.php with out success. Can any of you PHP professionals tell me how to do this ??? |
That sounds like your local CA file is missing or out of date. Tweaking the class is a bad idea (because it's hard to maintain), and it's fixing the symptom, not the cause. Fix the cause and the symptom will go away. |
Hi Synchro ! Thanks for looking. I reviewed my xampp php7 setup and found that I had neglected to set Once that was set and the cacert.pem file copied into place, everything operated as expected. Thanks again for the assistance. I will send an email on an off-topic item that I hope you can assist with. |
I'm pretty happy that this script now works with the new 5.5 branch, so I'm closing it. FYI I ran into the cacert problem sa swell and it turned out to be a problem with the libcurl my PHP was using - it was built with libressl. I recompiled with openssl and it all started working, so I added a note to the troubleshooting guide about it. |
Greetings! I'd like to tell you about my last journey, it was full of adventures, please read more here http:https://sufrapari.urgentchildcareusa.com/e4vxxrv My best to you, ljlorente |
Hello! I thought you were interested in stuff like that, so probably that article would be helpful to you, please read it here http:https://nkeltiquewi.clintsantiagodahl.com/e4vklzbf In haste, ljlorente |
Hi! We've been at a very nice place recently and we loved it so much, I think it is just a fantastic place, check it out http:https://quovoxachy.hhotechnologies.com/e4xod Be well, ljlorente |
Dear friend! Yours faithfully, ljlorente |
Yo! We have recently had a splendid dinner with my family in a great place, just take a look http:https://ltiwinyly.shorttalent.com/e4dsoufg Typos courtesy of my iPhone, ljlorente |
I have been trying to get the gmail_xoauth.phps example running from the github site for a number of days now following these instructions.
https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2
I have repeated the instructions faithfully and googled the error and followed the suggestions on this forum to no avail.
I always end with "SMTP ERROR: AUTH command failed: 334".
(The format presented at the google developers site is now slightly different from that shown in the instructions.)
The only difference from the instructions up to the point of failure is the absence of
250-CHUNKING in the SERVER -> CLIENT response.
Here is my current state. Can anyone offer suggestions as to how I can get closer to a solution ?
(confidential information replaced by xxxxx)
The following change was made to php.ini to get to this point.
[cURL] curl.cainfo = C:\xampp\php\cacert.pem
This code was also added to gmail_xoauth.php
// LAD, 2016-04-05 // unsecure fix for "Warning: stream_socket_enable_crypto(): SSL operation failed with code 1"
// see #368
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
php version = 5.6.15
PHPMailer version = 5.2.14
Apache version = Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.15
redo steps at https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2
https://console.developers.google.com/project
Create project
project name: phpmailer3
project id: phpmailer3-1273
app engine location: us-central
Google APIs
click Gmail API
click Enable Gmail API
This API is enabled, but you can't use it in your project until you create credentials.
Click "Go to Credentials" to do this now (strongly recommended).
Now select Credentials from the left-hend menu, then click the Create new Client ID button:
click Create Credentials button
Which API ? Gmail API
Calling API from ? Web Server
What data ? User data
click 'What credentials do I need ?'
Calling Gmail API from a web server
2 Create an OAuth 2.0 client ID
name: phpmailer3
authorized redirect uri: https://localhost/phpmailer2/get_oauth_token.php
click 'Create client ID'
Created OAuth client 'phpmailer3'
Email address '[email protected]'
Product name shown to users 'PHPMailer3'
click 'Continue'
Download credentials
Client ID
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
paste the new values into get_oauth_token.php
$redirectUri = 'http:https://localhost/phpmailer2/get_oauth_token.php';
$clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxx';
Fetch the token with get_oauth_token.php
Refresh Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
paste the new values into gmail_xoauth.php and try again
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP 31sm483745ioj.17 - gsmtp
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [xx.xxx.xxx.xx]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [xx.xxx.xxx.xx]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250 SMTPUTF8
CLIENT -> SERVER: AUTH XOAUTH2 dXNlcj1sb3JuZWR1ZGxleUBnbWFpbC5jb20BYXV0aD1CZWFyZXIgeWEyOS4udkFKeDE1U1plODFQOHlQLWMwN29qMDFjM0VtT3ZFTTlUMFVHZzV6bFF0dkRUQ0poaWdIVXUydl9fQk1uOGstVDRRAQE=
SERVER -> CLIENT: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
SMTP ERROR: AUTH command failed: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
SMTP Error: Could not authenticate.
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/answer/14257 31sm483745ioj.17 - gsmtp
SMTP ERROR: QUIT command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/answer/14257 31sm483745ioj.17 - gsmtp
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
The text was updated successfully, but these errors were encountered: