简体   繁体   English

如何使用 c++ 代码通过 cmd 发送 email?

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

I am new to c++, currently trying to make a program that sends me email.我是 c++ 的新手,目前正在尝试制作一个向我发送 email 的程序。 I have seen a couple of codes but none worked on my program:我看过一些代码,但没有一个适用于我的程序:

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);
}

or或者

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");
}

I cant send an email from cmd but not from a c++ code/program.我不能从 cmd 发送 email 但不能从 c++ 代码/程序发送。

How can i send an email with attachment from c++ program?如何发送带有 c++ 程序附件的 email?

Use below libcurl options while sending 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);

For more information refer below articles:有关更多信息,请参阅以下文章:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM