我正在尝试通过smtp通过gmail帐户使用libcurl发送电子邮件。我正在使用你可以在这里下载的预编译二进制文件http://curl.haxx.se/download.html 7.39.0 for Win32 - Generic。
我尝试了http://talkbinary.com/programming/c/how-to-send-email-through-gmail-using-libcurl/所描述的内容,但得到了不同的结果。他基本上遵循了libcurl的smtp-tls示例。他写道,他取消注释了这一行
curl_easy_setopt(curl, CURLOPT_CAINFO,"/path/to/certificate.pem");
我也这样做了,但另外我必须添加
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
否则它说:
* Rebuilt URL to: smtp://smtp.gmail.com:587/
* Hostname was NOT found in DNS cache
* Trying 173.194.65.108...
* Connected to smtp.gmail.com (173.194.65.108) port 587 (#0)
< 220 mx.google.com ESMTP cp4sm38701354wjb.16 - gsmtp
> EHLO shire
< 250-mx.google.com at your service, [84.166.177.243]
< 250-SIZE 35882577
< 250-8BITMIME
< 250-STARTTLS
< 250-ENHANCEDSTATUSCODES
< 250-PIPELINING
< 250-CHUNKING
< 250 SMTPUTF8
> STARTTLS
< 220 2.0.0 Ready to start TLS
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0
所以经过这些修改,我得到了这个:
* Rebuilt URL to: smtp://smtp.gmail.com:587/
* Hostname was NOT found in DNS cache
* Trying 173.194.65.109...
* Connected to smtp.gmail.com (173.194.65.109) port 587 (#0)
< 220 mx.google.com ESMTP q7sm28257004wiv.8 - gsmtp
> EHLO shire
< 250-mx.google.com at your service, [84.166.177.243]
< 250-SIZE 35882577
< 250-8BITMIME
< 250-STARTTLS
< 250-ENHANCEDSTATUSCODES
< 250-PIPELINING
< 250-CHUNKING
< 250 SMTPUTF8
> STARTTLS
< 220 2.0.0 Ready to start TLS
* SSL connection using unknown / ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=smtp.gm
ail.com
* start date: 2014-07-15 08:40:38 GMT
* expire date: 2015-04-04 15:15:55 GMT
* issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
* SSL certificate verify result: unable to get local issuer certificate (
20), continuing anyway.
> EHLO shire
< 250-mx.google.com at your service, [84.166.177.243]
< 250-SIZE 35882577
< 250-8BITMIME
< 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
< 250-ENHANCEDSTATUSCODES
< 250-PIPELINING
< 250-CHUNKING
< 250 SMTPUTF8
> AUTH LOGIN
< 334 VXNlcm5hbWU6
> bXRlY2hzeXNhZG1AZ21haWwuY29t
< 334 UGFzc3dvcmQ6
> anFTTzIzb1RjSDlzTU9nZDc4cnE=
< 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsb
uZo
< 534-5.7.14 7VOvzOT0OTtJcazYiOGpbaceOY427PX1CQ2gpC8wMVG5AHhSl_Hpp4pe0O1hdm5Jm5w
b9V
< 534-5.7.14 VjK_OdeEkhSuQejNA2ghBemuoPSzEXyz0ycnpQpV6Rm4Korpi5wuo4c6RcmH3o13usA
1vN
< 534-5.7.14 ryZaFNuIF8jMSXiUsiP5lPC9vK1Ll7d9fRxM_vSbIDzUOxeid1iMeBJab3us2M6RxMW
tZt
< 534-5.7.14 A5XYkt7z8nbX8W1gdCiDOGtKvqd4> Please log in via your web browser an
d
< 534-5.7.14 then try again.
< 534-5.7.14 Learn more at
< 534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 q7sm2825
7004wiv.8 - gsmtp
* Authentication failed: 534
* Closing connection 0
我尝试访问此网址https://support.google.com/mail/bin/answer.py?answer=78754和https://www.google.com/accounts/DisplayUnlockCaptcha并尝试了那里写的内容。我认为我的密码很强。我用KeePass2生成它。我可以使用gmail Web界面访问该gmail帐户。我的登录名/密码是正确的。我现在多次检查过。