Mikhail
Mikhail

Reputation: 13

How to add attachments to e-mail on curl

I want to attach a text file to the message, which is located in the folder with the program, but I can't. A file with a size of 0 bytes is attached.

#define FROM    "<[email protected]>"
#define TO      "<[email protected]>"
#define TITLE     "MY_NAME" FROM

static const char *payload_text[] = {
  "To: " TO "\r\n",
  "From: " TITLE " \r\n",
  "Subject: Theme\r\n",
  "\r\n",
  "Content-Type: text/plain\r\n",
  "Content-Transfer-Encoding: base64\r\n",
  "Content-Disposition: inline; filename=file.txt\r\n",
  "\r\n",
  NULL
};

int main(void)
{
    CURL *curl;
    CURLcode res = CURLE_OK;
    ...
}

There was an idea to attach html, but it is also impossible to attach it to a message using this method.

Upvotes: 1

Views: 656

Answers (1)

Shawn
Shawn

Reputation: 52529

As can be seen in the following excerpt from this useful example program, you need to use curl_mime_filedata() if you want to attach a file to an email:

/* Add the current source program as an attachment. */ 
part = curl_mime_addpart(mime);
curl_mime_filedata(part, "smtp-mime.c");

Upvotes: 1

Related Questions