Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <curl/curl.h>
  4.  
  5. #define FROM "<svetlio1994@gmail.com>"
  6. #define TO "<dekov94@gmail.com>"
  7.  
  8. static const char *payload_text[] = {
  9. "To: " TO "\r\n",
  10. "From: " FROM "\r\n",
  11. "Subject: shiiit\r\n",
  12. NULL
  13. };
  14.  
  15. struct upload_status {
  16. int lines_read;
  17. };
  18.  
  19. static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp)
  20. {
  21. struct upload_status *upload_ctx = (struct upload_status *)userp;
  22. const char *data;
  23.  
  24. if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
  25. return 0;
  26. }
  27.  
  28. data = payload_text[upload_ctx->lines_read];
  29.  
  30. if(data) {
  31. size_t len = strlen(data);
  32. memcpy(ptr, data, len);
  33. upload_ctx->lines_read++;
  34.  
  35. return len;
  36. }
  37.  
  38. return 0;
  39. }
  40.  
  41. int main(void)
  42. {
  43. CURL *curl;
  44. CURLcode res = CURLE_OK;
  45. struct curl_slist *recipients = NULL;
  46. struct upload_status upload_ctx;
  47.  
  48. upload_ctx.lines_read = 0;
  49.  
  50. curl = curl_easy_init();
  51. if(curl) {
  52. curl_easy_setopt(curl, CURLOPT_USERNAME, "svetlio1994@gmail.com");
  53. curl_easy_setopt(curl, CURLOPT_PASSWORD, "");
  54. curl_easy_setopt(curl, CURLOPT_URL, "smtp://smtp.gmail.com:587");
  55. curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
  56. curl_easy_setopt(curl, CURLOPT_CAINFO, "google.pem");
  57. curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);
  58. recipients = curl_slist_append(recipients, TO);
  59. //curl_easy_setopt(curl, CURLOPT_FILE, "edgE0DF.tmp");
  60. curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
  61. curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
  62. curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
  63. curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
  64. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  65.  
  66. res = curl_easy_perform(curl);
  67.  
  68. if(res != CURLE_OK)
  69. fprintf(stderr, "curl_easy_perform() failed: %s\n",
  70. curl_easy_strerror(res));
  71.  
  72. curl_slist_free_all(recipients);
  73.  
  74. curl_easy_cleanup(curl);
  75. }
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement