smtp-vrfy.c 2.6 KB

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