curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Need directions on how to use curl with gmail smtp and OAuth2

From: ToddAndMargo via curl-users <curl-users_at_cool.haxx.se>
Date: Wed, 18 Mar 2020 02:03:30 -0700

On 2020-03-16 16:23, ToddAndMargo via curl-users wrote:
> Hi All,
>
> Does anyone have a link to a good set of directions on
> how to use curl with smtp.gmail.com and Oauth2?
>
> Many thanks,
> -T

Help!

Fedora 31
curl-7.66.0-1.fc31.x86_6

gMail: less secure apps are purposefully off as gMail will be dropping
support for less secure in June.

I can not find anything our there on how to use curl with
gmail and OAuth2.

I did figure out how to get my token:

   First, you must obtain your Client ID and Client Secret by using
   a browser. Open the following

      https://console.developers.google.com/
      --> Credentials (left column)
        --> "+ Create Credentials" (button at the top)
           --> OAuth client ID
             --> Application Type = Web Application
               --> Name: give it a unique name
                 --> Save
                   --> copy the resulting Client ID and Client Secret
                       into the corresponding variables below.
                       And independently save these values as well

   The script will then take you to a browser page where you will
   sign into your google account to receive your
   authorization code, which you save

   Also note that you have to tell gmail that the suspecious activity is
you.
   gmail will send you a letter with a link to follow

client_id="aaaa" # from the web page
client_secret="bbb" # also from the web page
scope="https://www.googleapis.com/auth/drive"
endpoint="https://accounts.google.com/o/oauth2/auth"=code&scope=$scope%access_type=offline&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
url="$endpoint?client_id=$client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=$scope&response_type=code"

This is what I have so far

$ cat mail.txt | curl -vvv smtp://smtp.gmail.com:465 --mail-from
"xxxx_at_gmail.com" --mail-rcpt "yyyy_at_zoho.com" --ssl -u
xxxx_at_gmail.com:'zzzz' -oauth2-bearer 'big long thing'

   % Total % Received % Xferd Average Speed Time Time Time
Current
                                  Dload Upload Total Spent Left
Speed
   0 0 0 0 0 0 0 0 --:--:-- --:--:--
--:--:-- 0* Trying 74.125.142.109:465...
* TCP_NODELAY set
* Connected to smtp.gmail.com (74.125.142.109) port 465 (#0)
   0 0 0 0 0 0 0 0 --:--:-- 0:00:09
--:--:-- 0* response reading failed
   0 0 0 0 0 0 0 0 --:--:-- 0:00:10
--:--:-- 0
* Closing connection 0
curl: (56) response reading failed
* Trying 0.0.0.4:80...
* TCP_NODELAY set
<hangs for about five minutes>
* connect to 0.0.0.4 port 80 failed: Connection timed out
* Failed to connect to 4 port 80: Connection timed out
* Closing connection 1
curl: (7) Failed to connect to 4 port 80: Connection timed out

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-03-18