Hi Steve, Daniel,

>> Please note: with the CURLOPT_HTTPPROXYTUNNEL option still in place, I 
>> am able to succeed with the curl_easy_perform anyway (and even send a 
>> mail), for the case where I do not use the gmail or other external mail 
>> servers.
>>
>> However, when I connect to an external mail server (such as gmail), I 
>> get the following logs:
>>
>> * About to connect() to smtp.gmail.com port 465 (#0)

> This looks wrong as libcurl here tries to connect to the remote host and it 
> seems you want to use a proxy. You're supposed to have entered a proxy as 
> well, as CURLOPT_HTTPPROXYTUNNEL only changes how it uses > the specified 
> (HTTP) proxy. You need to provide the proxy name and port separately.

>> *   Trying 173.194.68.108... * Connection refused
> ... clearly you can't connect directly to these hosts on port 465. Nothing 
> libcurl can do much about!

Thanks for your patience. Per your suggestion, I modified my code to include 
the proxy URL and port values explicitly. 
Post those (and a few other) changes (I've attached the code for your 
reference), I get the following error logs:

* About to connect() to proxy web-proxy.cup.hp.com port 8080 (#0)
*   Trying 16.216.235.20... * connected
* Connected to xxxxxxxxxx (xx.xxx.xxx.xx) port 8080 (#0)
* Establish HTTP proxy tunnel to smtp.gmail.com:587
* Server auth using Basic with user '[email protected]'
> CONNECT smtp.gmail.com:587 HTTP/1.1
Host: smtp.gmail.com:587
Proxy-Connection: Keep-Alive

< HTTP/1.1 200 Connection established
<
* Proxy replied OK to CONNECT request
< 220 mx.google.com ESMTP u15sm12534619anq.14
> EHLO xxxx.yyy.zzz.com
< 250-mx.google.com at your service, [15.211.201.85]
< 250-SIZE 35882577
< 250-8BITMIME
< 250-STARTTLS
< 250-ENHANCEDSTATUSCODES
< 250 PIPELINING
* No known auth mechanisms supported!
> QUIT
< 221 2.0.0 closing connection u15sm12534619anq.14
* Closing connection #0
* Login denied

Again, w.r.t the above, kindly note:
1) I am using curl v7.28.1 to verify my test case.
2) I tried including the saved 'gmail server certificate location' in the code 
(and passed it to CURLOPT_CAINFO).
3) I am using perfectly valid gmail username/password credentials.
4) I have added the CURLOPT_USE_SSL option (with value CURLUSESSL_ALL), since a 
few archived libcurl solutions indicated the inclusion of this option as having 
solved the auth issue 
     (but the issue persists for mine nevertheless).

Kindly let me know if you might still find anything amiss.

Thanks,
Naveen

#include <string.h>
#include "curl/curl.h"

/* Message text */
static const char *payload[] =
{
    "This is a test mail.\n",
    NULL
};

struct upload_status
{
    int lines_read;
};

static size_t read_callback ( 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[upload_ctx->lines_read];

    if (data)
    {
        size_t len = strlen(data);
        memcpy ( ptr, data, len );
        upload_ctx->lines_read++;
        return len;
    }

    return 0;  /* when there is no more data to deliver */
}

int main ( void )
{
    CURL *curl;
    CURLcode curl_result;
    struct upload_status foo;
    struct curl_slist *recipients = NULL;

    foo.lines_read = 0;

    curl_global_init ( CURL_GLOBAL_DEFAULT );

    curl = curl_easy_init();
    if ( curl )
    {
        struct curl_slist* rcpt_list = NULL;

        curl_easy_setopt ( curl, CURLOPT_PROXY, "http://xxxxxxxxx:8080"; );
        //curl_easy_setopt ( curl, CURLOPT_PROXYPORT, 8080 );
        curl_easy_setopt ( curl, CURLOPT_HTTPPROXYTUNNEL, 1L );
        curl_easy_setopt ( curl, CURLOPT_USE_SSL, CURLUSESSL_ALL );
        //curl_easy_setopt ( curl, CURLOPT_SSL_VERIFYPEER, 0L );
        //curl_easy_setopt ( curl, CURLOPT_SSL_VERIFYHOST, 0L );
        //curl_easy_setopt ( curl, CURLOPT_USE_SSL, CURLUSESSL_TRY );

        curl_easy_setopt ( curl, CURLOPT_URL, "smtp://smtp.gmail.com:587" );
        curl_easy_setopt ( curl, CURLOPT_CAINFO, 
"/home/naveen/gmail_certificate.crt");
        curl_easy_setopt ( curl, CURLOPT_USERNAME, "[email protected]" );
        curl_easy_setopt ( curl, CURLOPT_PASSWORD, "xxxxxxx" );
        //curl_easy_setopt ( curl, CURLOPT_TLSAUTH_USERNAME, "[email protected]" );
        //curl_easy_setopt ( curl, CURLOPT_TLSAUTH_PASSWORD, "xxxxxxx" );

        curl_easy_setopt ( curl, CURLOPT_MAIL_FROM, "[email protected]" );

        rcpt_list = curl_slist_append ( rcpt_list, "[email protected]" );
        curl_easy_setopt ( curl, CURLOPT_MAIL_RCPT, rcpt_list );

        curl_easy_setopt ( curl, CURLOPT_READFUNCTION, read_callback );
        curl_easy_setopt ( curl, CURLOPT_READDATA, &foo );
        curl_easy_setopt ( curl, CURLOPT_VERBOSE, 1 );

        curl_result = curl_easy_perform ( curl );

        curl_slist_free_all ( rcpt_list );
        curl_easy_cleanup ( curl );
        curl_global_cleanup();

        return 0;
    }

    else
    {
        printf ( "Error: %d", curl_result );
        return -1;
    }
}
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to