cURL / Mailing Lists / curl-library / Single Mail


Re: IMAP/SMTP/POP3 examples

From: Ben Greear <>
Date: Wed, 02 Jun 2010 16:28:11 -0700

On 06/02/2010 11:59 AM, Alona Rossen wrote:
> Were you able to hack libcurl to get IMAP working?
> Can you provide us or submit some SMTP/POP2/IMAP examples.

I have a hack that works for me, but it may not work for the
multi interface.

Please check out my curl.ct repository:

git clone git://

If you're using c-ares, ask me for a patch for local binding.
I haven't gotten the man pages written so it's not merged
upstream yet.

I don't have any snippets of code that make sense by themselves,
but here are some of the URLs my app supports (and it passes these
URLs directly to curl in most cases). For POP, I get a listing,
parse it, and then download all those messages with individual
libcurl requests.

     * Download a specific email id with IMAP:
     * Download all email for this user with IMAP:
     * Download all email in INBOX for this user with IMAP:
     * Download all email in INBOX with POP3:
     * Send email with SSL security using SMTP:
     * Send email with SSL security using SMTP, use script to generate random email text:
       Select 'Get-URLs-From-File'
       specify file in URL textbox: smtp_urls.txt
       The file should have contents similar to:

       system ' > /tmp/smtp_script_mail.txt'
       ul smtps:// /tmp/smtp_script_mail.txt

The curl EASY SETOPS docs describe all various settings that pertain to
each protocol, for instance:

    if ((strncasecmp(cur_url->getUrl(), "smtp:", 5) == 0) ||
        (strncasecmp(cur_url->getUrl(), "smtps:", 5) == 0)) {
       if ((rv = curl_easy_setopt(curl, CURLOPT_MAIL_FROM, (const char*)(smtp_from))) != CURLE_OK) {
          VLOG_ERR(VLOG << "CURL setup error, MAIL_FROM, err: " << rv
                   << " smtp_from -:" << smtp_from << ":-" << endl);
          return -1;

       // NOTE: Re-using user_agent's really SMTP 'to' here.
       VLOG << "Setting SMTP-TO to -:" << user_agent << ":-\n";
       smtp_to_slist = NULL;
       smtp_to_slist = curl_slist_append(smtp_to_slist, user_agent);
       if ((rv = curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, smtp_to_slist)) != CURLE_OK) {
          VLOG_ERR(VLOG << "CURL setup error, MAIL_RCPT, err: " << rv << " smtp-to -:" << user_agent << ":-\n");
          return -1;


Ben Greear <>
Candela Technologies Inc
List admin:
Received on 2010-06-03