Advertisement
Momir

CURL

Feb 12th, 2020
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <curl/curl.h>
  4.  
  5. int main(void)
  6. {
  7.     CURL* curl;
  8.     CURLcode res = CURLE_OK;
  9.  
  10.     curl = curl_easy_init();
  11.     if (curl) {
  12.         struct curl_slist* recipients = NULL;
  13.         curl_mime* mime;
  14.         curl_mimepart* part;
  15.         const char** cpp;
  16.  
  17.         curl_easy_setopt(curl, CURLOPT_URL, "smtps://smtp.gmail.com:465");
  18.         curl_easy_setopt(curl, CURLOPT_USERNAME, "tvoje.ime@gmail.com");
  19.         curl_easy_setopt(curl, CURLOPT_PASSWORD, "TvojaSifra");
  20.         recipients = curl_slist_append(recipients, "ime.primalac@gmail.com");
  21.         curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
  22.  
  23.         mime = curl_mime_init(curl);
  24.         part = curl_mime_addpart(mime);
  25.         curl_mime_filedata(part, "Ime (adresa) fajla za slanje");
  26.         curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
  27.  
  28.         res = curl_easy_perform(curl);
  29.  
  30.         if (res != CURLE_OK)
  31.             fprintf(stderr, "Nije poslato, error: %s\n", curl_easy_strerror(res));
  32.  
  33.         curl_slist_free_all(recipients);
  34.         curl_easy_cleanup(curl);
  35.         curl_mime_free(mime);
  36.     }
  37.  
  38.     return (int)res;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement