Hi Steve,
Attempting to run the attached SMTP code (for sending a sample mail from a
valid gmail mail account to another, using gmail's SMTP server) fails.
I've tried with ports 25, 465 and 587, but without success.
Even trying to use the 'CURLUSESSL_ALL' option along with the
CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST set to zero do not seem to
work!
Kindly let me know if I am missing something very basic here.
Thanks,
Naveen
#include <string.h>
#include "curl/curl.h"
/* Sender / Recipient addresses */
#define FROM ("<[email protected]>")
#define TO ("<[email protected]>")
/* 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_HTTPPROXYTUNNEL, 1L );
curl_easy_setopt ( curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL );
curl_easy_setopt ( curl, CURLOPT_SSL_VERIFYPEER, 0L );
curl_easy_setopt ( curl, CURLOPT_SSL_VERIFYHOST, 0L );
curl_easy_setopt ( curl, CURLOPT_URL, "smtp://smtp.gmail.com:465" );
curl_easy_setopt ( curl, CURLOPT_USERNAME, "[email protected]" );
curl_easy_setopt ( curl, CURLOPT_PASSWORD, "xxxxx" );
curl_easy_setopt ( curl, CURLOPT_MAIL_FROM, FROM );
rcpt_list = curl_slist_append ( rcpt_list, TO );
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