2020-11-05 16:53:02 +08:00
|
|
|
/***************************************************************************
|
2013-12-31 21:22:40 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2013-12-31 21:22:40 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2013-12-31 21:22:40 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2013-12-31 21:22:40 +08:00
|
|
|
***************************************************************************/
|
2015-11-22 19:55:10 +08:00
|
|
|
|
|
|
|
/* <DESC>
|
2022-11-22 17:57:55 +08:00
|
|
|
* Verify an SMTP email address
|
2015-11-22 19:55:10 +08:00
|
|
|
* </DESC>
|
|
|
|
*/
|
|
|
|
|
2013-12-31 21:22:40 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2021-12-17 18:02:18 +08:00
|
|
|
/* This is a simple example showing how to verify an email address from an
|
2013-12-31 21:22:40 +08:00
|
|
|
* SMTP server.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
*
|
2014-01-06 06:59:29 +08:00
|
|
|
* 1) This example requires libcurl 7.34.0 or above.
|
2013-12-31 21:22:40 +08:00
|
|
|
* 2) Not all email servers support this command and even if your email server
|
|
|
|
* does support it, it may respond with a 252 response code even though the
|
2021-10-31 23:34:44 +08:00
|
|
|
* address does not exist.
|
2013-12-31 21:22:40 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
CURL *curl;
|
|
|
|
CURLcode res;
|
|
|
|
struct curl_slist *recipients = NULL;
|
|
|
|
|
|
|
|
curl = curl_easy_init();
|
|
|
|
if(curl) {
|
2014-01-05 18:32:47 +08:00
|
|
|
/* This is the URL for your mailserver */
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com");
|
2013-12-31 21:22:40 +08:00
|
|
|
|
|
|
|
/* Note that the CURLOPT_MAIL_RCPT takes a list, not a char array */
|
|
|
|
recipients = curl_slist_append(recipients, "<recipient@example.com>");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
|
|
|
|
|
|
|
|
/* Perform the VRFY */
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
|
|
|
/* Check for errors */
|
|
|
|
if(res != CURLE_OK)
|
|
|
|
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
|
|
|
curl_easy_strerror(res));
|
|
|
|
|
|
|
|
/* Free the list of recipients */
|
|
|
|
curl_slist_free_all(recipients);
|
|
|
|
|
2021-10-31 23:34:44 +08:00
|
|
|
/* curl will not send the QUIT command until you call cleanup, so you
|
|
|
|
* should be able to re-use this connection for additional requests. It
|
|
|
|
* may not be a good idea to keep the connection open for a very long time
|
|
|
|
* though (more than a few minutes may result in the server timing out the
|
2013-12-31 21:22:40 +08:00
|
|
|
* connection) and you do want to clean up in the end.
|
|
|
|
*/
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|