I am working on a project in C++, which includes a feature of sending information to someone as \'email attachment\'.
Everything is done except this \'email\' thing.
Download cURL from here, and extract. Now, run the executable from C++ code using WinExec()
from windows.h
.
Here is a demonstration for Gmail:
#include
int main(void){
char* command = "curl smtp://smtp.gmail.com:587 -v --mail-from \"SENDER.EMAIL@gmail.com\" --mail-rcpt \"RECEIVER.EMAIL@gmail.com\" --ssl -u SENDER.EMAIL@gmail.com:PASSWORD -T \"ATTACHMENT.FILE\" -k --anyauth";
WinExec(command, SW_HIDE);
return 0;
}
Place curl.exe in the same directory. Enter your email address and password in the command
. Here, message is saved in a text file (ATTACHMENT.FILE).
Caution: The command
may not support some special characters (like- &
).
The above is just a demonstration of cURL. For practical usage you should go for libcurl. Here is a head-start for sending mail (works both with Windows and Linux).