smtp-expn.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2014, 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. #include <stdio.h>
  23. #include <string.h>
  24. #include <curl/curl.h>
  25. /* This is a simple example showing how to expand an email mailing list.
  26. *
  27. * Notes:
  28. *
  29. * 1) This example requires libcurl 7.34.0 or above.
  30. * 2) Not all email servers support this command.
  31. */
  32. int main(void)
  33. {
  34. CURL *curl;
  35. CURLcode res;
  36. struct curl_slist *recipients = NULL;
  37. curl = curl_easy_init();
  38. if(curl) {
  39. /* This is the URL for your mailserver */
  40. curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com");
  41. /* Note that the CURLOPT_MAIL_RCPT takes a list, not a char array */
  42. recipients = curl_slist_append(recipients, "Friends");
  43. curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
  44. /* Set the EXPN command */
  45. curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "EXPN");
  46. /* Perform the custom request */
  47. res = curl_easy_perform(curl);
  48. /* Check for errors */
  49. if(res != CURLE_OK)
  50. fprintf(stderr, "curl_easy_perform() failed: %s\n",
  51. curl_easy_strerror(res));
  52. /* Free the list of recipients */
  53. curl_slist_free_all(recipients);
  54. /* Curl won't send the QUIT command until you call cleanup, so you should
  55. * be able to re-use this connection for additional requests. It may not be
  56. * a good idea to keep the connection open for a very long time though
  57. * (more than a few minutes may result in the server timing out the
  58. * connection) and you do want to clean up in the end.
  59. */
  60. curl_easy_cleanup(curl);
  61. }
  62. return 0;
  63. }