Envio Email con C++???
Publicado por Mari Carmen (1 intervención) el 21/11/2002 13:31:01
Alguien me puede explicar como enviar un email sin abrir Outlook? Gracias..
Valora esta pregunta


0
start mailto:destinatario@example.com?subject=Asunto&body=Este es el cuerpo del mensaje
#include <iostream>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "smtp://smtp.example.com:587"); // Cambia esto por tu servidor SMTP
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, "<tu_email@example.com>");
// Lista de destinatarios
struct curl_slist *recipients = NULL;
recipients = curl_slist_append(recipients, "<destinatario@example.com>");
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
// Contenido del mensaje
const char *message = "To: destinatario@example.com\r\n"
"From: tu_email@example.com\r\n"
"Subject: Asunto\r\n"
"\r\n"
"Este es el cuerpo del mensaje.\r\n";
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_READDATA, message);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
// Enviar el correo
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
}
// Limpiar
curl_slist_free_all(recipients);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}