C ++在退出时发送电子邮件

时间:2015-10-15 15:31:35

标签: c++ email send atexit

我要做的是在退出程序时发送电子邮件。 我使用atexit();函数来执行此操作,但是...它无法正常工作。

#include <windows.h>
#include <iostream>

void SendEmail()
{
    //lot of code here
}

void Print()
{
    std::cout << "Bye!";
    system("pause");
}

void Terminate()
{
    SendEmail(blahblah); // Doesn't work
    Print(); // Works
}

int main()
{
    atexit(Terminate);

    while (true) Sleep(1);
    return 0;
}

SendEmail();函数是否需要花费太多时间而且什么都不做?它甚至不打印服务器响应(在main();

中使用时效果很好

1 个答案:

答案 0 :(得分:3)

您不知道在atexit运行之前已关闭其他资源。这些对于SendMail的成功运行非常重要。