---
name: "curl_mime_init"
section: "3"
platform: "linux"
package: "curl"
version: "8.23.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "macos"]
url: "https://new.carta.tech/curl_mime_init"
---

# curl\_mime\_init(3)

create a mime handle

## NAME

curl\_mime\_init - create a mime handle

## SYNOPSIS

```
#include <curl/curl.h>
curl_mime *curl_mime_init(CURL *easy_handle);
```

## DESCRIPTION

*[curl\_mime\_init(3)](/curl_mime_init/3.md)* creates a handle to a new empty mime structure. This mime structure can be subsequently filled using the mime API, then attached to some easy handle using option *[CURLOPT\_MIMEPOST(3)](/CURLOPT_MIMEPOST/3.md)* within a *[curl\_easy\_setopt(3)](/curl_easy_setopt/3.md)* call or added as a multipart in another mime handle's part using *[curl\_mime\_subparts(3)](/curl_mime_subparts/3.md)*.

*easy\_handle* is used for part separator randomization and error reporting. Since 7.87.0, it does not need to be the final target handle.

Using a mime handle is the recommended way to post an HTTP form, format and send a multi-part email with SMTP or upload such an email to an IMAP server.

## PROTOCOLS

This functionality affects http, imap and smtp

## EXAMPLE

```
int main(void)
{
  CURL *easy = curl_easy_init();
  curl_mime *mime;
  curl_mimepart *part;
  /* Build an HTTP form with a single field named "data", */
  mime = curl_mime_init(easy);
  part = curl_mime_addpart(mime);
  curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
  curl_mime_name(part, "data");
  /* Post and send it. */
  curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
  curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
  curl_easy_perform(easy);
  /* Clean-up. */
  curl_easy_cleanup(easy);
  curl_mime_free(mime);
}
```

## AVAILABILITY

Added in curl 7.56.0

## RETURN VALUE

A mime struct handle, or NULL upon failure.

## SEE ALSO

[**CURLOPT\_MIMEPOST**(3)](/CURLOPT_MIMEPOST/3.md), [**curl\_mime\_addpart**(3)](/curl_mime_addpart/3.md), [**curl\_mime\_free**(3)](/curl_mime_free/3.md), [**curl\_mime\_subparts**(3)](/curl_mime_subparts/3.md)
