#include #include "Poco/Net/MailMessage.h" #include "Poco/Net/MailRecipient.h" #include "Poco/Net/SMTPClientSession.h" #include "Poco/Net/NetException.h" #include "Poco/Net/SecureSMTPClientSession.h" #include "Poco/Net/InvalidCertificateHandler.h" #include "Poco/Net/AcceptCertificateHandler.h" #include "Poco/Net/SSLManager.h" #include "Poco/Net/SecureStreamSocket.h" #include "Poco/Net/StringPartSource.h" #include "Poco/Net/MailMessage.h" #include using Poco::Net::InvalidCertificateHandler; using Poco::Net::AcceptCertificateHandler; using Poco::Net::Context; using Poco::Net::SSLManager; using Poco::Net::SecureStreamSocket; using Poco::Net::SocketAddress; using Poco::Net::SecureSMTPClientSession; using Poco::Net::SMTPClientSession; using Poco::SharedPtr; using Poco::Net::MailMessage; using Poco::Net::MailRecipient; using Poco::Net::StringPartSource; //g++ poco.cpp -Wl,--start-group -Wl,-Bstatic -lPocoJSON -lPocoXML -lPocoUtil -lPocoCrypto -lPocoNetSSL -lPocoNet -lPocoFoundation -Wl,--end-group -Wl,-Bdynamic -lpthread -lssl -lcrypto -ldl -lm -o poco int main(int argc, char** argv) { std::string host = "send.one.com"; int port = 465; std::string sUserName = "werner@blohm.com"; std::string sPassword = "Spacewalk1955"; std::string to = "werner@signerink.dk"; std::string from = "werner@blohm.com"; std::string subject = "Your first e-mail message sent using Poco Libraries æøåÆØÅ"; std::string content = "Well done! You've successfully https://blohm.com sent your first message using Poco SMTPClientSession æøåÆØÅ"; /* std::string content(""); content += ""; content += ""; content += ""; content += ""; content += "Test HTML"; content += ""; content += "";*/ MailMessage message; try { SharedPtr pCert = new AcceptCertificateHandler(false); Context::Ptr pContext = new Poco::Net::Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); SSLManager::instance().initializeClient(0, pCert, pContext); SecureStreamSocket pSSLSocket(pContext); pSSLSocket.connect(SocketAddress(host, port)); SecureSMTPClientSession secure(pSSLSocket); // Create a timespan of (e.g.) 6 secs Poco::Timespan ts(6L, 0L); secure.setTimeout(ts); secure.login(); bool tlsStarted = secure.startTLS(pContext); secure.login(SMTPClientSession::AUTH_LOGIN, sUserName, sPassword); message.setSender(from); message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, to)); message.setSubject(subject); message.setContentType("text/plain; charset=UTF-8"); //message.setContentType("text/html; charset=utf-8"); //message.setContent(content, MailMessage::ENCODING_8BIT); message.addContent( new StringPartSource( content ) ); message.addAttachment("myFile", new Poco::Net::FilePartSource("/home/rock/linphonerc.txt")); message.addAttachment( "ip4.sh", new Poco::Net::FilePartSource( "/home/rock/ip4.sh" ) ); message.addAttachment( "session.php", new Poco::Net::FilePartSource( "/home/rock/session.php" ) ); secure.sendMessage(message); secure.close(); } catch (Poco::Net::SMTPException &e) { std::cout << e.code() << std::endl; std::cout << e.message() << std::endl; std::cout << e.what() << std::endl; std::cout << e.displayText().c_str() << std::endl; } catch (Poco::Net::NetException &e) { std::cout << e.code() << std::endl; std::cout << e.message() << std::endl; std::cout << e.what() << std::endl; std::cout << e.displayText().c_str() << std::endl; } return 0; }