1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
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 https://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 ***************************************************************************/
29 * This is the list of basic details you need to tweak to get things right.
31 #define USERNAME "user@example.com"
32 #define PASSWORD "123qwerty"
33 #define RECIPIENT "<1507-recipient@example.com>"
34 #define MAILFROM "<1507-realuser@example.com>"
36 #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
38 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
44 return CURL_READFUNC_ABORT;
52 int still_running = 1;
53 struct timeval mp_start;
54 struct curl_slist *rcpt_list = NULL;
56 curl_global_init(CURL_GLOBAL_DEFAULT);
62 rcpt_list = curl_slist_append(rcpt_list, RECIPIENT);
63 /* more addresses can be added here
64 rcpt_list = curl_slist_append(rcpt_list, "<others@example.com>");
67 curl_easy_setopt(curl, CURLOPT_URL, URL);
69 curl_easy_setopt(curl, CURLOPT_USERNAME, USERNAME);
70 curl_easy_setopt(curl, CURLOPT_PASSWORD, PASSWORD);
72 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
73 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
74 curl_easy_setopt(curl, CURLOPT_MAIL_FROM, MAILFROM);
75 curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
76 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
77 multi_add_handle(mcurl, curl);
79 mp_start = tutil_tvnow();
81 /* we start some action by calling perform right away */
82 curl_multi_perform(mcurl, &still_running);
84 while(still_running) {
85 struct timeval timeout;
86 int rc; /* select() return code */
99 /* set a suitable timeout to play around with */
103 curl_multi_timeout(mcurl, &curl_timeo);
104 if(curl_timeo >= 0) {
105 timeout.tv_sec = curl_timeo / 1000;
106 if(timeout.tv_sec > 1)
109 timeout.tv_usec = (curl_timeo % 1000) * 1000;
112 /* get file descriptors from the transfers */
113 curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd);
115 /* In a real-world program you OF COURSE check the return code of the
116 function calls. On success, the value of maxfd is guaranteed to be
117 greater or equal than -1. We call select(maxfd + 1, ...), specially in
118 case of (maxfd == -1), we call select(0, ...), which is basically equal
121 rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
123 if(tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) {
124 fprintf(stderr, "ABORTING TEST, since it seems "
125 "that it would have run forever.\n");
133 case 0: /* timeout */
134 default: /* action */
135 curl_multi_perform(mcurl, &still_running);
142 curl_slist_free_all(rcpt_list);
143 curl_multi_remove_handle(mcurl, curl);
144 curl_multi_cleanup(mcurl);
145 curl_easy_cleanup(curl);
146 curl_global_cleanup();