smtp-expn.c 2.5 KB

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