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 ***************************************************************************/
26 static char buffer[17000]; /* more than 16K */
31 CURLcode res = CURLE_OK;
32 curl_mime *mime = NULL;
34 struct curl_slist *recipients = NULL;
36 /* create a buffer with AAAA...BBBBB...CCCC...etc */
38 int size = (int)sizeof(buffer) / 10;
40 for(i = 0; i < size ; i++)
41 memset(&buffer[i * 10], 65 + (i % 26), 10);
43 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
44 fprintf(stderr, "curl_global_init() failed\n");
45 return TEST_ERR_MAJOR_BAD;
48 curl = curl_easy_init();
50 fprintf(stderr, "curl_easy_init() failed\n");
51 res = (CURLcode) TEST_ERR_MAJOR_BAD;
55 /* Build mime structure. */
56 mime = curl_mime_init(curl);
58 fprintf(stderr, "curl_mime_init() failed\n");
59 res = (CURLcode) TEST_ERR_MAJOR_BAD;
62 part = curl_mime_addpart(mime);
64 fprintf(stderr, "curl_mime_addpart() failed\n");
65 res = (CURLcode) TEST_ERR_MAJOR_BAD;
68 res = curl_mime_filename(part, "myfile.jpg");
70 fprintf(stderr, "curl_mime_filename() failed\n");
73 res = curl_mime_type(part, "image/jpeg");
75 fprintf(stderr, "curl_mime_type() failed\n");
78 res = curl_mime_data(part, buffer, sizeof buffer);
80 fprintf(stderr, "curl_mime_data() failed\n");
83 res = curl_mime_encoder(part, "base64");
85 fprintf(stderr, "curl_mime_encoder() failed\n");
89 /* Prepare recipients. */
90 recipients = curl_slist_append(NULL, "someone@example.com");
92 fprintf(stderr, "curl_slist_append() failed\n");
96 /* First set the URL that is about to receive our mime mail. */
97 test_setopt(curl, CURLOPT_URL, URL);
100 test_setopt(curl, CURLOPT_MAIL_FROM, "somebody@example.com");
102 /* Set recipients. */
103 test_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
105 /* send a multi-part mail */
106 test_setopt(curl, CURLOPT_MIMEPOST, mime);
108 /* get verbose debug output please */
109 test_setopt(curl, CURLOPT_VERBOSE, 1L);
111 /* Perform the request, res will get the return code */
112 res = curl_easy_perform(curl);
117 curl_easy_cleanup(curl);
119 /* now cleanup the mime structure */
120 curl_mime_free(mime);
122 /* cleanup the recipients. */
123 curl_slist_free_all(recipients);
125 curl_global_cleanup();