不想说话(努力写buging) 2023-01-22 21:00 采纳率: 83.3%
浏览 50
已结题

C语言curl smtp发送邮件登录被拒绝

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;

}

错误信息

img

  • 写回答

3条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-01-22 22:04
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 1月24日
  • 已采纳回答 1月23日
  • 修改了问题 1月22日
  • 创建了问题 1月22日

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭