CURLOPT_MAIL_RCPT(3)

πŸ’Œ CURLOPT_MAIL_RCPT πŸ’Œ

okay so this is the CURLOPT_MAIL_RCPT page from the Library Functions Manual, and it's basically the "who are we even sending this email to bestie" option. let's get into it πŸ’…


✨ NAME ✨

CURLOPT_MAIL_RCPT β€” the list of SMTP mail recipients, aka the guest list for your little email party πŸŽ€


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAIL_RCPT,
                          struct curl_slist *rcpts);

✨ DESCRIPTION ✨

so you pass in a pointer to a linked list of recipients and that's who gets hit up in your SMTP mail request πŸ“¬ the linked list has to be a fully valid list of struct curl_slist structs, properly filled in, no half-baked vibes. use curl_slist_append(3) to build the list and curl_slist_free_all(3) to clean up a whole list when you're done 🧹

⚠️ important bestie: libcurl does not copy the list. it does not. so you have to keep that list alive and kicking until after the transfer has completed. if you free it early you're gonna have a bad time 😭

when you're doing a mail transfer, each recipient should be specified inside a pair of angled brackets (<>). however β€” and this is the cute part β€” if the first character is not an angled bracket, libcurl just assumes you gave it a single email address and wraps that address in brackets for you 🫢 (she's thoughtful like that)

if you want to specify DSN parameters (as per RFC 3461), the address has to be written in angled brackets, followed by the parameters. no shortcuts there πŸ”₯

when you're doing an address verification (that's the VRFY command), each recipient should be specified as the username or username plus domain (as per Section 3.5 of RFC 5321) πŸ¦‹

when you're doing a mailing list expand (the EXPN command), each recipient should be specified using the mailing list name, like Friends or London-Office πŸ‘‘

and oop, one thing β€” using this option multiple times makes the last set list override the previous ones. so it's giving "last one wins" energy. set it to NULL to disable its use again πŸ’€


✨ DEFAULT ✨

NULL


✨ PROTOCOLS ✨

this functionality affects smtp only. just smtp. that's it. that's the whole list πŸ’…


✨ EXAMPLE ✨

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    struct curl_slist *list;
    list = curl_slist_append(NULL, "root@localhost");
    list = curl_slist_append(list, "person@example.com");
    list = curl_slist_append(list, "<other@example.com> NOTIFY=SUCCESS");
    curl_easy_setopt(curl, CURLOPT_URL, "smtp://example.com/");
    curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, list);
    result = curl_easy_perform(curl);
    curl_slist_free_all(list);
    curl_easy_cleanup(curl);
  }
}

look at her go πŸ₯Ή note that the third one uses the angled brackets <> plus DSN parameters, while the first two just get auto-wrapped. iconic behaviour.


✨ AVAILABILITY ✨

added in curl 7.20.0 β€” she's been around a minute ⭐


✨ RETURN VALUE ✨

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK πŸŽ‰ non-zero means an error occurred β€” go check libcurl-errors(3) for the tea πŸ™ˆ


✨ SEE ALSO ✨


okay that's the whole page, mwah πŸ’– this one's from libcurl, dated 2026-10-12, and the page name is still CURLOPT_MAIL_RCPT(3) in case you forgot where you were πŸŽ€ now go send that mail bestie πŸ¦‹βœ¨

πŸ“¦ where this page comes from