簡體   English   中英

如何使用 c++ 代碼通過 cmd 發送 email?

[英]How can i send an email through cmd using c++ code?

我是 c++ 的新手,目前正在嘗試制作一個向我發送 email 的程序。 我看過一些代碼,但沒有一個適用於我的程序:

void sendData(){
    
    char* command = "Transmit smtp://smtp.gmail.com:587 -v --mail-from \"your.email@gmail.com\" --mail-rcpt \"your.email@gmail.com\" --ssl -u your.email@gmail.com:password -T \"Record.log\" -k --anyauth";
    WinExec(command, SW_HIDE);
}

或者

void send(){ 
     system("curl smtps://smtp.gmail.com:465 -v --mail-from \"email@gmail.com\" --mail-rcpt \"email@gmail.com\" --ssl -u email@gmail.com:***** -T \"mail.txt\": -k --anyauth");
}

我不能從 cmd 發送 email 但不能從 c++ 代碼/程序發送。

如何發送帶有 c++ 程序附件的 email?

在發送 email 時使用以下 libcurl 選項:-

curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_size); 
curl_easy_setopt(curl, CURLOPT_READFUNCTION, fileBuf_source);
curl_easy_setopt(curl, CURLOPT_READDATA, &file_upload_ctx);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);

res = curl_easy_perform(curl);

有關更多信息,請參閱以下文章:

https://www.codeproject.com/Questions/714669/Sending-Email-with-attachment-using-libcurl

https://curl.se/libcurl/c/smtp-mail.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM