1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 2014, Steve Holme, <steve_holme@hotmail.com>.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
27 * This is the list of basic details you need to tweak to get things right.
29 #define TO "<recipient@example.com>"
30 #define FROM "<sender@example.com>"
32 static const char *payload_text[] = {
33 "From: different\r\n",
46 struct upload_status {
50 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
52 struct upload_status *upload_ctx = (struct upload_status *)userp;
55 if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
59 data = payload_text[upload_ctx->lines_read];
62 size_t len = strlen(data);
63 memcpy(ptr, data, len);
64 upload_ctx->lines_read++;
76 struct curl_slist *rcpt_list = NULL;
77 struct upload_status upload_ctx = {0};
79 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
80 fprintf(stderr, "curl_global_init() failed\n");
81 return TEST_ERR_MAJOR_BAD;
84 if((curl = curl_easy_init()) == NULL) {
85 fprintf(stderr, "curl_easy_init() failed\n");
86 curl_global_cleanup();
87 return TEST_ERR_MAJOR_BAD;
90 rcpt_list = curl_slist_append(rcpt_list, TO);
91 /* more addresses can be added here
92 rcpt_list = curl_slist_append(rcpt_list, "<others@example.com>");
95 test_setopt(curl, CURLOPT_URL, URL);
96 test_setopt(curl, CURLOPT_UPLOAD, 1L);
97 test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
98 test_setopt(curl, CURLOPT_READDATA, &upload_ctx);
99 test_setopt(curl, CURLOPT_MAIL_FROM, FROM);
100 test_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
101 test_setopt(curl, CURLOPT_VERBOSE, 1L);
103 res = curl_easy_perform(curl);
107 curl_slist_free_all(rcpt_list);
108 curl_easy_cleanup(curl);
109 curl_global_cleanup();