LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-10-2012, 05:34 PM   #1
patapout
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.

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

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;
}
Regards
 
  


Reply


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


All times are GMT -5. The time now is 12:58 PM.

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