我有什么选择在c ++中编写smtp客户端(跨平台)

时间:2009-08-02 04:21:37

标签: c++ smtp

我需要在我的应用程序中添加能力以发送电子邮件(使用用户的电子邮件服务器/服务),以便我需要使用或使用smtp c ++ lib或代码 其中我不知道在哪里找到。我在哪里可以找到我可以使用或学习的免费lib或源代码 你可以帮我解决这个问题 谢谢

6 个答案:

答案 0 :(得分:5)

我建议使用poco c ++库。这些是在Boost Software License(最非限制性的开源许可证之一)下发布的,它们将Mail-lib作为其中的一部分。这是他们的文件所说的:

  

通过支持电子邮件附件的SMTP(简单邮件传输协议,RFC 2821)服务器发送电子邮件的类,以及从POP3下载电子邮件的类(邮局协议版本3,RFC 1939)服务器。

Poco Website

的问候,
Ovanes

P.S。 Poco C ++ Libs是一个多平台框架。

答案 1 :(得分:1)

使用boost :: asio并按照协议规范编写一个简单的客户端。

答案 2 :(得分:0)

如果您不介意GPL许可,可以尝试VMime

如果您想要Windows库,可以尝试CPJNSMTPConnection

答案 3 :(得分:0)

在Unix下,从程序发送邮件的正常方式是将其包含(使用popen)传送到/ usr / lib / sendmail。其他MTA(后缀等)提供了与该接口的兼容性程序。

优点是您不必配置每个程序发送邮件,以便他们使用正确的网关,能够使用别名,...

答案 4 :(得分:0)

根据您的要求,ACE可能是一种选择。 它是一个免费的开源框架,可用于许多操作系统。

我不知道他们是否有针对smtp的具体实现,但至少他们为连接部分提供了C ++抽象。所以只有协议实现由你决定。

答案 5 :(得分:0)

以下是我的c ++ smtp客户端示例:带有附件的https://github.com/breakermind/SslSMTPClient并允许自动从收件人电子邮件域获取mx主机,并且您不需要自己的smtp服务器:

// main - create SSL context and connect
int main(int count, char *strings[])
{ 
    cout << "C++ ssl smtp send email with STARTTLS\r\n";    

    // Add attachments to message if you want
    vector<string> files;
    // files.push_back("file9.jpg");
    // files.push_back("filek.pdf");

    // Initialize
    sslsmtpEx sm;
    sm.sslsmtpExSet("localhost", 25); 

    // EHLO hostname
    sm.heloHostname("domain.pl");

    // Display logs
    // sm.showLogs();

    // get MX records from dns for recipient
    vector<string> mx = sm.getMX("email@gmail.com",0,0);

    // Send email to each mx host from recipient domain DNS ( You need send only to one server !!! )
    for (int i = 0; i < mx.size(); i++){

        // Set hostname from mx dns
        sm.sslsmtpExSet(mx.at(i), 25);
        cout << "Mx host: " << mx.at(i) << endl;    

        // send email
        int ok = sm.Send("email@domain.pl", "nanomoow@gmail.com", "email@domain.pl", "Smtp client test", "<h1>Smtp test</h1>", "<h1>Smtp test</h1>", files);

        cout << "Email has been sent : " <<  ok << endl;

        if(ok){
            // if email has been sent, end loop with next mxhost
            break;
        }            
    }
    sleep(10);

return 0;    
}

此致

相关问题