C语言smtp发送邮件登录被拒绝
#include <stdio.h>
#include <Windows.h>
#include "curl/curl/curl.h"
void printTIME(){
time_t t;
struct tm *p;
time(&t);
p = localtime(&t);
printf ("%d-%02d-%02d %02d:%02d:%02d ", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday,p->tm_hour, p->tm_min, p->tm_sec);
}
void send_verification_code(const char* email, const char* code) {
CURL *curl;
CURLcode res;
char post_data[256];
sprintf(post_data, "from=example@qq.com&to=%s&subject=Verification Code&body=Your verification code is %s.", email, code);
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_CAINFO, "cacert.pem");
curl_easy_setopt(curl, CURLOPT_URL, "smtp://smtp.qq.com:587");
curl_easy_setopt(curl, CURLOPT_USERNAME, "usename");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "password");
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, "usename");
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, email);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
printTIME();
printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
curl_global_cleanup();
}
int main(void) {
send_verification_code("to email", "123456");
system("pause");
return 0;
}
错误信息
