cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: IMAP/SMTP/POP3 examples

From: Alona Rossen <arossen_at_opentext.com>
Date: Thu, 3 Jun 2010 09:37:47 -0400

Hi Ben,

This is very helpful.

Thanks,
Alona

-----Original Message-----
From: Ben Greear [mailto:greearb_at_candelatech.com]
Sent: Wednesday, June 02, 2010 7:28 PM
To: libcurl development
Cc: Alona Rossen
Subject: Re: IMAP/SMTP/POP3 examples

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://dmz1.candelatech.com/curl.ct

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:
       imap://user:password_at_mail.candelatech.com/INBOX/;uid=1
     * Download all email for this user with IMAP:
       imap://user:password_at_mail.candelatech.com/
     * Download all email in INBOX for this user with IMAP:
       imap://user:password_at_mail.candelatech.com/INBOX?ALL
     * Download all email in INBOX with POP3:
       pop3://user:password_at_mail.candelatech.com/
     * Send email with SSL security using SMTP:
       smtps://user:password_at_mail.candelatech.com
     * 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 'update_email_txt.pl > /tmp/smtp_script_mail.txt'
       ul smtps://user:password_at_mail.candelatech.com
/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);
          stopOnError(getCurlErrBuffer());
          return -1;
       }

       // NOTE: Re-using user_agent string..it's really SMTP 'to' here.
       VLOG << "Setting SMTP-TO to -:" << user_agent << ":-\n";
       curl_slist_free_all(smtp_to_slist);
       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");
          stopOnError(getCurlErrBuffer());
          return -1;
       }
    }

Thanks,
Ben

-- 
Ben Greear <greearb_at_candelatech.com>
Candela Technologies Inc  http://www.candelatech.com
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-06-03