【发布时间】:2020-10-13 16:47:44
【问题描述】:
您好,我已经对此进行了搜索,但我无法弄清楚为什么这一直失败。我正在使用以下 curl 命令通过 gmail 帐户发送电子邮件。身份验证失败。
我尝试了两个帐户,一个具有应用密码的 2 因子设置,另一个仅启用了不太安全的应用。
两者都未能通过身份验证。
curl --ssl-reqd --url smtp://smtp.gmail.com:587 --mail-from myemail@gmail.com --mail-rcpt otheremail@gmail.com --user 'myemail@gmail.com:password' --cacert cacert.pem --upload-file mail.txt --TLSv1.2 --tls-max 1.2 --verbose
cacert.pem 来自这里https://curl.haxx.se/ca/cacert.pem
这是 curl 的输出
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 64.233.167.109:587...
* TCP_NODELAY set
* Connected to smtp.gmail.com (64.233.167.109) port 587 (#0)
< 220 smtp.gmail.com ESMTP v11sm289228wml.26 - gsmtp
> EHLO mail.txt
< 250-smtp.gmail.com at your service, [x.x.x.x]
< 250-SIZE 35882577
< 250-8BITMIME
< 250-STARTTLS
< 250-ENHANCEDSTATUSCODES
< 250-PIPELINING
< 250-CHUNKING
< 250 SMTPUTF8
> STARTTLS
< 220 2.0.0 Ready to start TLS
* successfully set certificate verify locations:
* CAfile: c:\utils\curl-7.68.0-win64-mingw\bin\cacert.pem
CApath: none
} [5 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [208 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [91 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [2342 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [114 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [37 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-ECDSA-CHACHA20-POLY1305
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google LLC; CN=smtp.gmail.com
* start date: Sep 22 15:25:59 2020 GMT
* expire date: Dec 15 15:25:59 2020 GMT
* subjectAltName: host "smtp.gmail.com" matched cert's "smtp.gmail.com"
* issuer: C=US; O=Google Trust Services; CN=GTS CA 1O1
* SSL certificate verify ok.
} [5 bytes data]
> EHLO mail.txt
{ [5 bytes data]
< 250-smtp.gmail.com at your service, [x.x.x.x]
< 250-SIZE 35882577
< 250-8BITMIME
< 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
< 250-ENHANCEDSTATUSCODES
< 250-PIPELINING
< 250-CHUNKING
< 250 SMTPUTF8
} [5 bytes data]
> AUTH PLAIN
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0{ [5 bytes data]
< 334
} [5 bytes data]
> ACdhbmR5cGRzMjAxNEBnbWFpbC5jb20AYW9ub3hubnB2Y3N3aGR1bic=
{ [5 bytes data]
< 535-5.7.8 Username and Password not accepted. Learn more at
< 535 5.7.8 https://support.google.com/mail/?p=BadCredentials v11sm289228wml.26 - gsmtp
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
* Closing connection 0
} [5 bytes data]
* TLSv1.2 (OUT), TLS alert, close notify (256):
} [2 bytes data]
curl: (67) Login denied```
I cannot see why this is not working, I can use the app password in another app that does not use OAuth and that lets me send emails OK.
I'm new to using curl and any help will be apricated.
Thanks.
Andy.
Edit: I have also tried this on my linuxVM and that worked fined with GMail, so I tried again in windows and still failed. I just removed the quotes from the user field and it worked fine.
【问题讨论】:
标签: windows curl command-line gmail