summaryrefslogtreecommitdiff
path: root/xs_curl.h
diff options
context:
space:
mode:
authorGravatar shtrophic2025-01-20 19:43:42 +0100
committerGravatar shtrophic2025-01-20 19:43:42 +0100
commit4e3d596bee1cee2c4146265eb6ac827f09820c53 (patch)
tree372c707d7b0cce189670f2a9ca31f65a44888253 /xs_curl.h
parentUpdated RELEASE_NOTES. (diff)
downloadpenes-snac2-4e3d596bee1cee2c4146265eb6ac827f09820c53.tar.gz
penes-snac2-4e3d596bee1cee2c4146265eb6ac827f09820c53.tar.xz
penes-snac2-4e3d596bee1cee2c4146265eb6ac827f09820c53.zip
add xs_smtp_request
Diffstat (limited to '')
-rw-r--r--xs_curl.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/xs_curl.h b/xs_curl.h
index f0cfd98..886aee0 100644
--- a/xs_curl.h
+++ b/xs_curl.h
@@ -9,6 +9,9 @@ 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
12#ifdef XS_IMPLEMENTATION 15#ifdef XS_IMPLEMENTATION
13 16
14#include <curl/curl.h> 17#include <curl/curl.h>
@@ -194,6 +197,39 @@ xs_dict *xs_http_request(const char *method, const char *url,
194 return response; 197 return response;
195} 198}
196 199
200int xs_smtp_request(const char *url, const char *user, const char *pass,
201 const char *from, const char *to, const xs_str *body)
202{
203 CURL *curl;
204 CURLcode res = CURLE_OK;
205 struct curl_slist *rcpt = NULL;
206 struct _payload_data pd = {
207 .data = (char *)body,
208 .size = xs_size(body),
209 .offset = 0
210 };
211
212 curl = curl_easy_init();
213
214 curl_easy_setopt(curl, CURLOPT_URL, url);
215 curl_easy_setopt(curl, CURLOPT_USERNAME, user);
216 curl_easy_setopt(curl, CURLOPT_PASSWORD, pass);
217
218 curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);
219 curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt = curl_slist_append(rcpt, to));
220
221 curl_easy_setopt(curl, CURLOPT_READDATA, &pd);
222 curl_easy_setopt(curl, CURLOPT_READFUNCTION, _post_callback);
223 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
224
225 res = curl_easy_perform(curl);
226
227 curl_slist_free_all(rcpt);
228 curl_easy_cleanup(curl);
229
230 return (int)res;
231}
232
197#endif /* XS_IMPLEMENTATION */ 233#endif /* XS_IMPLEMENTATION */
198 234
199#endif /* _XS_CURL_H */ 235#endif /* _XS_CURL_H */