Advertisement
opera

Untitled

Oct 19th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.56 KB | None | 0 0
  1. /***************************************************************************
  2. *                                  _   _ ____  _
  3. *  Project                     ___| | | |  _ \| |
  4. *                             / __| | | | |_) | |
  5. *                            | (__| |_| |  _ <| |___
  6. *                             \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22.  
  23. #include <stddef.h>
  24. #include <stdlib.h>
  25. #include <curl/curl.h>
  26.  
  27. const char* cacert_filepath = "";
  28. int smtp_port = 25;
  29. const char* smtp_host = "";
  30. const char* smtp_login = "";
  31. const char* smtp_password = "";
  32. const char* sender_email = "";
  33. const char* recipient = "";
  34. FILE* f = fopen("test.eml","rb");
  35.  
  36. int main(void)
  37. {
  38.  
  39.     curl_global_init(CURL_GLOBAL_ALL );
  40.     CURL* curl_ptr = curl_easy_init();
  41.     if(!curl_ptr)
  42.         return 1;
  43.  
  44.     curl_easy_setopt(curl_ptr,CURLOPT_TIMEOUT,120);
  45.  
  46.     curl_easy_setopt(curl_ptr, CURLOPT_USE_SSL, CURLUSESSL_ALL);
  47.     curl_easy_setopt(curl_ptr, CURLOPT_SSL_VERIFYPEER,1);
  48.     curl_easy_setopt(curl_ptr, CURLOPT_SSL_VERIFYHOST, 2);
  49.     curl_easy_setopt(curl_ptr, CURLOPT_CAINFO, cacert_filepath);
  50.     curl_easy_setopt(curl_ptr, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT);
  51.     curl_easy_setopt(curl_ptr, CURLOPT_SSL_SESSIONID_CACHE, 1);
  52.  
  53.     curl_easy_setopt(curl_ptr, CURLOPT_URL, smtp_host);
  54.     curl_easy_setopt(curl_ptr, CURLOPT_PORT, smtp_port);
  55.     curl_easy_setopt(curl_ptr, CURLOPT_USERNAME, smtp_login);
  56.     curl_easy_setopt(curl_ptr, CURLOPT_PASSWORD, smtp_password);
  57.     curl_easy_setopt(curl_ptr, CURLOPT_MAIL_FROM, sender_email);
  58.  
  59.     struct curl_slist* rcpt_list = NULL;
  60.     rcpt_list = curl_slist_append(rcpt_list, recipient);
  61.     curl_easy_setopt(curl_ptr, CURLOPT_MAIL_RCPT, rcpt_list);
  62.  
  63.     curl_easy_setopt(curl_ptr, CURLOPT_READDATA, f);
  64.  
  65.     CURLcode error_code = curl_easy_perform(curl_ptr);
  66.     if(error_code != CURLE_OK)
  67.         return 1;
  68.  
  69.     curl_slist_free_all(rcpt_list);
  70.     curl_easy_cleanup(curl_ptr);
  71.     curl_global_cleanup();
  72.     fclose(f);
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement