Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-10-2012, 05:34 PM   #1
LQ Newbie
Registered: Jan 2012
Posts: 25

Rep: Reputation: Disabled
Can't send file attachment with curl

Hi, I want to send a file in the seem directory of my program binary. When I receive the email, I can see a link to attachement myfile.txt but when click on it, I don't get the file content but the message body content instread. I am misssing something but don't know what it is.

curl_easy_setopt(hnd, CURLOPT_READFUNCTION, payload_source);
  curl_easy_setopt(hnd, CURLOPT_READDATA, &upload_ctx);
static const char *payload_text[]={
    "To: <>\n",
    "From: <>(Example User)\n",
    "Content-Type: text/plain\n",
    "Content-Disposition: attachment; filename=\"myfile.txt\"\n",
    "Subject: Hello!\n",
    "Message sent\n",

struct upload_status {
    int lines_read;

static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp){
    struct upload_status *upload_ctx = (struct upload_status *)userp;
    const char *data;

    if ((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
    return 0;

    data = payload_text[upload_ctx->lines_read];
    if (data) {
    size_t len = strlen(data);
    memcpy(ptr, data, len);
    upload_ctx->lines_read ++;
    return len;
return 0;


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I send mail with attachment using Perl? oihsu21 Programming 3 06-29-2012 03:49 AM
convert email files with attachment to save as attachment file (metamail?) ted_chou12 Linux - Software 2 04-08-2011 09:01 PM
cURL: Server has many IPs, how would I make a cURL script use those IPs to send data? guest Programming 0 04-11-2009 12:42 PM
How to send a html file as an file attachment to my mail from crontab? GRD Linux - Newbie 2 06-03-2008 12:39 PM
send mails with attachment ProXXXy Linux - Networking 2 08-18-2004 04:33 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:15 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration