Windows Curl命令行通过gmail发送电子邮件

Windows Curl命令行通过gmail发送电子邮件,windows,curl,command-line,gmail,Windows,Curl,Command Line,Gmail,嗨,我已经对此进行了搜索,我不知道为什么它一直失败。我使用下面的curl命令通过gmail帐户发送电子邮件。身份验证失败 我尝试了两个帐户,一个是使用应用程序密码进行双因素设置的帐户,另一个只是启用了不太安全的应用程序 两者都无法进行身份验证 curl--ssl请求--urlsmtp://smtp.gmail.com:587 --寄自myemail@gmail.com--邮件rcptotheremail@gmail.com--用户指南myemail@gmail.com:password'--ca

嗨,我已经对此进行了搜索,我不知道为什么它一直失败。我使用下面的curl命令通过gmail帐户发送电子邮件。身份验证失败

我尝试了两个帐户,一个是使用应用程序密码进行双因素设置的帐户,另一个只是启用了不太安全的应用程序

两者都无法进行身份验证

curl--ssl请求--urlsmtp://smtp.gmail.com:587 --寄自myemail@gmail.com--邮件rcptotheremail@gmail.com--用户指南myemail@gmail.com:password'--cacert cacert.pem--upload file mail.txt--TLSv1.2--tls max 1.2--verbose

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.



Dload上传总左速度
0 0 0 0 0 0 0--:-:-:-:---:-:---:---0*正在尝试64.233.167.109:587。。。
*TCP_节点集
*已连接到smtp.gmail.com(64.233.167.109)端口587(#0)
<220 smtp.gmail.com ESMTP v11sm289228wml.26-gsmtp
>EHLO mail.txt
<250-smtp.gmail.com为您服务,[x.x.x.x]
<250-尺寸35882577
<250-8bit
<250-STARTTLS
<250-增强状态码
<250-流水线
<250-分块
<250 SMTPUTF8
>STARTTLS
<220 2.0.0准备启动TLS
*已成功设置证书验证位置:
*CAfile:c:\utils\curl-7.68.0-win64-mingw\bin\cacert.pem
卡帕斯:没有
}[5字节数据]
*TLSv1.2(输出),TLS握手,客户端问候(1):
}[208字节数据]
*TLSv1.2(IN)、TLS握手、服务器hello(2):
{[91字节数据]
*TLSv1.2(IN),TLS握手,证书(11):
{[2342字节数据]
*TLSv1.2(IN)、TLS握手、服务器密钥交换(12):
{[114字节数据]
*TLSv1.2(IN),TLS握手,服务器完成(14):
{[4字节数据]
*TLSv1.2(输出)、TLS握手、客户端密钥交换(16):
}[37字节数据]
*TLSv1.2(OUT),TLS更改密码,更改密码规范(1):
}[1字节数据]
*TLSv1.2(输出),TLS握手,完成(20):
}[16字节数据]
*TLSv1.2(IN),TLS握手,完成(20):
{[16字节数据]
*使用TLSv1.2/ECDHE-ECDSA-CHACHA20-POLY1305的SSL连接
*服务器证书:
*主题:C=US;ST=California;L=Mountain View;O=Google LLC;CN=smtp.gmail.com
*开始日期:9月22日15:25:59格林尼治标准时间2020
*到期日期:12月15日15:25:59格林威治标准时间2020
*subjectAltName:主机“smtp.gmail.com”与证书的“smtp.gmail.com”匹配
*发卡机构:C=US;O=Google Trust Services;CN=GTS CA 1O1
*SSL证书验证正常。
}[5字节数据]
>EHLO mail.txt
{[5字节数据]
<250-smtp.gmail.com为您服务,[x.x.x.x]
<250-尺寸35882577
<250-8bit
<250-AUTH登录普通XOAUTH2普通客户端令牌OAuthXOAuth
<250-增强状态码
<250-流水线
<250-分块
<250 SMTPUTF8
}[5字节数据]
>认证平原
0 0 0 0 0 0 0--::-->:-->:-->:------0{[5字节数据]
< 334
}[5字节数据]
>ACDHBMR5CGRZMJAXNEBNBFPBC5JB20AYW9UB3HUBNB2 Y3N3GR1BIC=
{[5字节数据]
<535-5.7.8不接受用户名和密码。了解更多信息,请访问
< 535 5.7.8  https://support.google.com/mail/?p=BadCredentials v11sm289228wml.26-gsmtp
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
*正在关闭连接0
}[5字节数据]
*TLSv1.2(输出)、TLS警报、关闭通知(256):
}[2字节数据]
curl:(67)登录被拒绝```
我不明白为什么这不起作用,我可以在另一个不使用OAuth的应用程序中使用应用程序密码,这样我就可以发送电子邮件了。
我对使用curl还不熟悉,任何帮助都会被忽略。
谢谢
安迪。
编辑:我也曾在我的linuxVM上尝试过这个,它在GMail上也能工作,所以我在windows上再次尝试,但仍然失败。我刚刚删除了用户字段中的引号,效果很好。

因此,正如我在编辑后的问题中所说的那样。我已经解决了

用户的myemail@gmail.com:password“需要从中删除单引号,它现在连接并发送邮件

希望这将有助于其他人在未来