I had a customer today that said he was not able to connect to his gmail SMTP server from his php script. So to test connectivity to gmail, I did the following test.
SSH to the server the customer is on.
Next you need to generate an auth string to use against the mail server. To do this, run the following
perl -MMIME::Base64 -e 'print encode_base64("\000myemail\@gmail.com\000mypassword")'
- Replace myemail\@gmail.com with your own gmail address
- Replace mypassword with your own gmail password
- leave the \000 intact, as that is a required part of the command
- You ‘ll get a response that looks something like this: AG15ZW1haWxAZ21haWwuY29tAG15cGFzc3dvcmQ=. You’ll need this for the AUTH section bellow
Now we need to open a connection to gmail. To do this, use the following 2 commands:
openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof
Now we need to authenticate. This is where the string we generated above comes into play.
AUTH PLAIN AG5pY2UudHJ5QGdtYWlsLmNvbQBub2l0c25vdG15cGFzc3dvcmQ=
- Replace AG5pY2UudHJ5QGdtYWlsLmNvbQBub2l0c25vdG15cGFzc3dvcmQ= with the string that was generated with the perl command above
Now that we are connected, we need to create the header of the email Use the following 4 commands to generate the header
MAIL FROM: <firstname.lastname@example.org>
RCPT TO: <email@example.com>
Now that the header has been created, we need to enter some data into the body of the email.
this is a test of the gmail mail system
- enter text, then press enter. Then add a single period on a line by itself to indicate that you have completed entering data
Once the email has sent, simply type quit. Now go check your recipeints email account to see if the email has come through.