curl-library
issue with using SMTP
Date: Tue, 24 Aug 2010 19:15:26 +0530
Hi,
I am writing a program to send email to a gmail account using SMTP. I am
specifying the username and password for the senders email id it is showing
syntax error. The code looks like this:
int main(int argc, char ** argv)
{
CURL *curl;
CURLcode res;
FILE * fd;
struct curl_slist * rcpt=NULL;
fd = fopen("text", "rb"); /* open file to upload */
curl = curl_easy_init();
if (curl)
{
printf(" setting options\n");
curl_easy_setopt(curl,CURLOPT_VERBOSE, 1);
//curl_easy_setopt(curl,CURLOPT_READDATA, fd);
curl_easy_setopt(curl,CURLOPT_URL,"smtp://gmail.com");
curl_easy_setopt(curl,CURLOPT_MAIL_FROM, "harshcalsoft_at_gmail.com");
rcpt = curl_slist_append(rcpt,"harshnitc_at_gmail.com");
curl_easy_setopt(curl,CURLOPT_MAIL_RCPT, rcpt);
curl_easy_setopt(curl,CURLOPT_USERNAME, argv[1]);
curl_easy_setopt(curl,CURLOPT_PASSWORD, argv[2]);
res = curl_easy_perform(curl);
printf("The return code is %d\n",res);
curl_slist_free_all(rcpt);
curl_easy_cleanup(curl);
}
fclose (fd);
return 0;
}
This is the output:
setting options
* About to connect() to smtp.gmail.com port 25 (#0)
* Trying 74.125.155.109... * connected
* Connected to smtp.gmail.com (74.125.155.109) port 25 (#0)
< 220 mx.google.com ESMTP 23sm130641wfa.10
> EHLO localhost
< 250-mx.google.com at your service, [219.91.201.210]
< 250-SIZE 35651584
< 250-8BITMIME
< 250-STARTTLS
< 250-ENHANCEDSTATUSCODES
< 250 PIPELINING
> MAIL FROM:harshcalsoft_at_gmail.com <FROM%3Aharshcalsoft_at_gmail.com>
< 530 5.7.0 Must issue a STARTTLS command first. 23sm130641wfa.10
* Access denied: 530
> QUIT
< 221 2.0.0 closing connection 23sm130641wfa.10
* Closing connection #0
* Login denied
The return code is 67
I am using the command line option with the following command:
curl --mail-from harshcalsoft_at_gmail.com --mail-rcpt harshnitc_at_gmail.com -v
-T text --url smtp://smtp.gmail.com -u harshcalsoft
we get the following output:
* About to connect() to smtp.gmail.com port 465 (#0)
* Trying 74.125.155.109... % Total % Received % Xferd Average
Speed Time Time Time Current
Dload Upload Total Spent Left
Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--
0connected
* Connected to smtp.gmail.com (74.125.155.109) port 465 (#0)
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSLv3, TLS handshake, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Server hello (2):
{ [data not shown]
* SSLv3, TLS handshake, CERT (11):
{ [data not shown]
* SSLv3, TLS handshake, Server finished (14):
{ [data not shown]
* SSLv3, TLS handshake, Client key exchange (16):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Finished (20):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
{ [data not shown]
* SSLv3, TLS handshake, Finished (20):
{ [data not shown]
* SSL connection using RC4-MD5
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=
smtp.gmail.com
* start date: 2010-04-22 20:02:45 GMT
* expire date: 2011-04-22 20:12:45 GMT
* common name: smtp.gmail.com (matched)
* issuer: C=US; O=Google Inc; CN=Google Internet Authority
* SSL certificate verify ok.
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:--
0< 220 mx.google.com ESMTP q17sm38872faa.45
> EHLO text
< 250-mx.google.com at your service, [219.91.201.210]
< 250-SIZE 35651584
< 250-8BITMIME
< 250-AUTH LOGIN PLAIN XOAUTH
< 250 ENHANCEDSTATUSCODES
> AUTH PLAIN aGFyc2hjYWxzb2Z0AGhhcnNoY2Fsc29mdABtb250eTAwNw==
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:--
0< 235 2.7.0 Accepted
> MAIL FROM:harshcalsoft_at_gmail.com <FROM%3Aharshcalsoft_at_gmail.com>
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:--
0< 555 5.5.2 Syntax error. q17sm38872faa.45
* Access denied: 555
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:--
0> QUIT
< 221 2.0.0 closing connection q17sm38872faa.45
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
} [data not shown]
curl: (67) Access denied: 555
Please help and how can we set the headers like subject , body etc for our
mail.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-08-24