• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_mime_init
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_MIMEPOST (3)
9  - curl_mime_addpart (3)
10  - curl_mime_free (3)
11  - curl_mime_subparts (3)
12---
13
14# NAME
15
16curl_mime_init - create a mime handle
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23curl_mime *curl_mime_init(CURL *easy_handle);
24~~~
25
26# DESCRIPTION
27
28curl_mime_init(3) creates a handle to a new empty mime structure.
29This mime structure can be subsequently filled using the mime API, then
30attached to some easy handle using option CURLOPT_MIMEPOST(3) within
31a curl_easy_setopt(3) call or added as a multipart in another mime
32handle's part using curl_mime_subparts(3).
33
34*easy_handle* is used for part separator randomization and error
35reporting. Since 7.87.0, it does not need to be the final target handle.
36
37Using a mime handle is the recommended way to post an HTTP form, format and
38send a multi-part email with SMTP or upload such an email to an IMAP server.
39
40# EXAMPLE
41
42~~~c
43int main(void)
44{
45  CURL *easy = curl_easy_init();
46  curl_mime *mime;
47  curl_mimepart *part;
48
49  /* Build an HTTP form with a single field named "data", */
50  mime = curl_mime_init(easy);
51  part = curl_mime_addpart(mime);
52  curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
53  curl_mime_name(part, "data");
54
55  /* Post and send it. */
56  curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
57  curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
58  curl_easy_perform(easy);
59
60  /* Clean-up. */
61  curl_easy_cleanup(easy);
62  curl_mime_free(mime);
63}
64~~~
65
66# AVAILABILITY
67
68As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
69
70# RETURN VALUE
71
72A mime struct handle, or NULL upon failure.
73