Send email with attachment in C++

前端 未结 5 2005
无人及你
无人及你 2020-12-01 00:10

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.

5条回答
  •  不思量自难忘°
    2020-12-01 00:49

    A Working Solution for Sending Email Using cURL


    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).

提交回复
热议问题