Hi ,
Libcurl is a utility tool which we can also send e-mails using SMTP library. Below is a sample program which helps you to do the same from Linux-C Language.
Below is the program
================
Libcurl is a utility tool which we can also send e-mails using SMTP library. Below is a sample program which helps you to do the same from Linux-C Language.
Below is the program
================
#include <stdio.h> #include <string.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; FILE *FP; struct curl_slist *recipients = NULL; static const char *from = "********@gmail.com"; static const char *to = "********@gmail.com"; FP=fopen("/tmp/Email","r"); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "smtp://smtp.gmail.com:587"); curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); curl_easy_setopt(curl, CURLOPT_USERNAME, "From_Email_User@gmail.com"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "*********"); curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from); recipients = curl_slist_append(recipients, to); curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); curl_easy_setopt(curl, CURLOPT_READDATA, FP); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); res = curl_easy_perform(curl); if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res)); curl_slist_free_all(recipients); curl_easy_cleanup(curl); } return 0; }File "/tmp/Email"
===============
[root@localhost ~]# more /tmp/Email Date: Mon, 29 Nov 2010 21:54:29 +1100, To: ***************@gmail, From: **********@gmail.com, Subject: Sample message, Content-Type: text/html; charset="us-ascii" Hi , How do you do. <b> Any html code </b>
How to Run
===========
[root@localhost ~]# gcc -o test test.c -lcurl;./test * Connection #0 to host smtp.gmail.com left intact > QUIT < 221 2.0.0 closing connection j9sm2235533pav.15 * Closing connection #0 [root@localhost ~]#à°¦ిà°¨ేà°·్ à°•ుà°®ాà°°్Dinesh Kumar
Comments
Post a Comment