C语言程序最终返回值3221225477
代码如下,部分参数涉及隐私,已做处理
#include <stdio.h>
#include "curl/curl/curl.h"
#include <string.h>
#include <Windows.h>
int send_email(char *from, char *to, char *subject, char *body, char *username, char *password)
{
CURL *curl;
CURLcode res = CURLE_OK;
struct curl_slist *recipients = NULL;
struct curl_slist *headers = NULL;
char data[1000]={0};
snprintf(data, 500, "from=%s&to=%s&subject=%s&body=%s&username=%s&password=%s", from, to, subject, body, username, password);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CAINFO, "cacert.pem");
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_URL, "smtp://smtp.163.com");
curl_easy_setopt(curl, CURLOPT_USERNAME, username);
curl_easy_setopt(curl, CURLOPT_PASSWORD, password);
curl_easy_setopt(curl, CURLOPT_LOGIN_OPTIONS, "AUTH=LOGIN");
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);
recipients = curl_slist_append(recipients, to);
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_READDATA, data);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
res = curl_easy_perform(curl);
if(res != CURLE_OK){
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
else
printf("%s","success");
curl_slist_free_all(recipients);
curl_easy_cleanup(curl);
}
return (int)res;
}
int main(void)
{
int result;
result = send_email("@163.com", "95@qq.com", "Test Email", "This is a test email.", "@163.com", "VGBBBSF");
system("pause");
}
终端运行
< 235 Authentication successful
> MAIL FROM:<@163.com>
< 250 Mail OK
> RCPT TO:<@qq.com>
< 250 Mail OK
> DATA
< 354 End data with <CR><LF>.<CR><LF>
--------------------------------
Process exited after 3.421 seconds with return value 3221225477
请按任意键继续. . .