• libcurl 库的使用方法


    首先要安装这个库,

    其次,要把需要的协议加上,./configure --enable-smtp --enable-pop3

    make

    make install

    使用curl --version 查看使用版本是否一样



    smtp代码实例:

    ###############################################################################

    #include <stdio.h>
    #include <curl/curl.h>

    size_t read_data(void *ptr, size_t size, size_t nmemb, void *data)
    {
    // FILE *fp = (FILE *)data;
    size_t return_size = fread(ptr, size, nmemb, data);
    printf("write %d\n", (int)return_size);
    return return_size;

    }
    int main()
    {
    CURL *curl;
    CURLcode res;

    FILE *fp = fopen("data.txt", "rb");
    if (fp == NULL) {
    printf("can't open \n");
    return -1;
    }
    struct curl_slist *slist=NULL;

    curl = curl_easy_init();
    if(curl) {
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
    curl_easy_setopt(curl, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_SSL);
    curl_easy_setopt(curl, CURLOPT_MAIL_FROM, "<mulinhai123@163.com>"); //发送者
    curl_easy_setopt(curl, CURLOPT_URL, "smtp://smtp.163.com");
    slist = curl_slist_append(slist, "<9191247@163.com>"); //接收者
    curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, slist);
    curl_easy_setopt(curl, CURLOPT_USERNAME, username);
    curl_easy_setopt(curl, CURLOPT_PASSWORD, password);
    curl_easy_setopt(curl, CURLOPT_READDATA, fp);
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_data);

    }
    res = curl_easy_perform(curl);

    printf("The return code is %d\n", res);

    fclose(fp);
    curl_slist_free_all(slist);
    curl_easy_cleanup(curl);

    return 0;
    }

    data.txt内容可以随便

    subject: test

    123

     

    转自:http://blog.sina.com.cn/s/blog_6026371d0100mqab.html 

  • 相关阅读:
    5.颜色空间转换
    Linux下的解压命令
    4.图像模糊/图像平滑
    insightface作者提供数据训练解读
    MXNetError: [05:53:50] src/operator/nn/./cudnn/cudnn_convolution-inl.h:287
    python中import cv2遇到的错误及安装方法
    docker 安装 mxnet
    95. Unique Binary Search Trees II
    236. Lowest Common Ancestor of a Binary Tree
    124. Binary Tree Maximum Path Sum
  • 原文地址:https://www.cnblogs.com/hnrainll/p/2140328.html
Copyright © 2020-2023  润新知