2009-08-02 19 views
-1

我需要添加在我的應用程序發送電子郵件(與用戶的電子郵件服務器/服務)的能力,因爲我需要wirth或使用smtp C++庫或代碼 其中我不知道在哪裏可以找到。我在哪裏可以找到免費的lib或源代碼,我可以使用或學習。
可以請你幫我在這個問題上 感謝有什麼選擇我必須寫在c + +(跨平臺)的smtp客戶

回答

0

下Unix,從程序發送郵件的正常方式是將其包含(用popen)管道傳送到/ usr/lib/sendmail。其他MTA(後綴等)提供與該接口的兼容性程序。

的好處是,你不必配置每個程序,以便他們使用的是正確的網關,能夠使用別名,發送郵件...

1

使用boost :: ASIO,並按照協議規範寫一個簡單的客戶端。

+0

到很多時間那.. 我繼電器需要跨平臺庫,順便說一句,因爲它只是協議,所以代碼可以爲每個操作系統..沒有? – user63898 2009-08-02 11:14:15

5

我會建議使用poco C++庫。這些都在Boost Software License(最具限制性的開源許可之一)下重新發布,並且它們以Mail-lib作爲它的一部分。這就是他們的文檔狀態:

類爲通過SMTP發送電子郵件(簡單郵件傳輸協議,RFC 2821)服務器與電子郵件附件的支持,以及類下載電子郵件來自POP3(郵局協議版本3,RFC 1939)服務器。

Poco Website

問候,
Ovanes

P.S. Poco C++ Libs是一個多平臺框架。

0

根據您的要求ACE可能是一個選項。 這是一個免費的開源框架,可用於很多操作系統。

我不知道他們是否具有smtp的具體實現,但至少他們提供連接部分的C++抽象。所以只有協議的實現取決於你。

0

這裏是我的C++ SMTP客戶端的例子:https://github.com/breakermind/SslSMTPClient帶附件,並允許得到收件人的電子郵件域名的MX主機automaticaly,你不需要自己的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 protected]",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 protected]", "[email protected]", "[email protected]", "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;  
} 

問候

相關問題