summaryrefslogtreecommitdiff
path: root/xs_curl.h
diff options
context:
space:
mode:
Diffstat (limited to 'xs_curl.h')
-rw-r--r--xs_curl.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/xs_curl.h b/xs_curl.h
index 657644a..0609a08 100644
--- a/xs_curl.h
+++ b/xs_curl.h
@@ -9,6 +9,10 @@ xs_dict *xs_http_request(const char *method, const char *url,
9 const xs_str *body, int b_size, int *status, 9 const xs_str *body, int b_size, int *status,
10 xs_str **payload, int *p_size, int timeout); 10 xs_str **payload, int *p_size, int timeout);
11 11
12int xs_smtp_request(const char *url, const char *user, const char *pass,
13 const char *from, const char *to, const xs_str *body,
14 int use_ssl);
15
12const char *xs_curl_strerr(int errnum); 16const char *xs_curl_strerr(int errnum);
13 17
14#ifdef XS_IMPLEMENTATION 18#ifdef XS_IMPLEMENTATION
@@ -196,6 +200,48 @@ xs_dict *xs_http_request(const char *method, const char *url,
196 return response; 200 return response;
197} 201}
198 202
203int xs_smtp_request(const char *url, const char *user, const char *pass,
204 const char *from, const char *to, const xs_str *body,
205 int use_ssl)
206{
207 CURL *curl;
208 CURLcode res = CURLE_OK;
209 struct curl_slist *rcpt = NULL;
210 struct _payload_data pd = {
211 .data = (char *)body,
212 .size = xs_size(body),
213 .offset = 0
214 };
215
216 curl = curl_easy_init();
217
218 curl_easy_setopt(curl, CURLOPT_URL, url);
219 if (user && pass) {
220 /* allow authless connections, to, e.g. localhost */
221 curl_easy_setopt(curl, CURLOPT_USERNAME, user);
222 curl_easy_setopt(curl, CURLOPT_PASSWORD, pass);
223 }
224
225 if (use_ssl)
226 curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
227
228 curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);
229
230 rcpt = curl_slist_append(rcpt, to);
231 curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt);
232
233 curl_easy_setopt(curl, CURLOPT_READDATA, &pd);
234 curl_easy_setopt(curl, CURLOPT_READFUNCTION, _post_callback);
235 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
236
237 res = curl_easy_perform(curl);
238
239 curl_easy_cleanup(curl);
240 curl_slist_free_all(rcpt);
241
242 return (int)res;
243}
244
199 245
200const char *xs_curl_strerr(int errnum) 246const char *xs_curl_strerr(int errnum)
201{ 247{