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