1
/*****************************************************************************
3
* Project ___| | | | _ \| |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
12
#include <curl/curl.h>
18
struct curl_slist *recipients = NULL;
20
/* value for envelope reverse-path */
21
static const char *from = "<bradh@example.com>";
23
/* this becomes the envelope forward-path */
24
static const char *to = "<bradh@example.net>";
26
curl = curl_easy_init();
28
/* this is the URL for your mailserver - you can also use an smtps:// URL
30
curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.net.");
32
/* Note that this option isn't strictly required, omitting it will result in
33
* libcurl will sent the MAIL FROM command with no sender data. All
34
* autoresponses should have an empty reverse-path, and should be directed
35
* to the address in the reverse-path which triggered them. Otherwise, they
36
* could cause an endless loop. See RFC 5321 Section 4.5.5 for more details.
38
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);
40
/* Note that the CURLOPT_MAIL_RCPT takes a list, not a char array. */
41
recipients = curl_slist_append(recipients, to);
42
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
44
/* You provide the payload (headers and the body of the message) as the
45
* "data" element. There are two choices, either:
46
* - provide a callback function and specify the function name using the
47
* CURLOPT_READFUNCTION option; or
48
* - just provide a FILE pointer that can be used to read the data from.
49
* The easiest case is just to read from standard input, (which is available
50
* as a FILE pointer) as shown here.
52
curl_easy_setopt(curl, CURLOPT_READDATA, stdin);
54
/* send the message (including headers) */
55
res = curl_easy_perform(curl);
57
/* free the list of recipients */
58
curl_slist_free_all(recipients);
60
/* curl won't send the QUIT command until you call cleanup, so you should be
61
* able to re-use this connection for additional messages (setting
62
* CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT as required, and calling
63
* curl_easy_perform() again. It may not be a good idea to keep the
64
* connection open for a very long time though (more than a few minutes may
65
* result in the server timing out the connection), and you do want to clean
68
curl_easy_cleanup(curl);