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