📄 example_5.cpp
字号:
#include <libsmtp++/inetsocket.h>#include <libsmtp++/smtp.h>#include <string>// This example shows how to use ssl encryption with// libsmtp++ without verifying the certificate of// the smtp server.//// compile with:// g++ -lsmtp++ example_5.cpp// the email message that is to be sent.string msg ="To: t_benk@web.de\n""Subject: test\n""\n""\n""test\n";main(){ // First put all informations together that we might need. string domain = "epost.de"; string from = "timo.benk@epost.de"; string host = "mail.epost.de"; unsigned int port = 25; // Then group all recipients in a vector. vector<string> rcpts; rcpts.push_back("t_benk@web.de"); rcpts.push_back("timo.benk@epost.de"); // Build the SMTP object. SMTP smtp ( domain, from, host, port ); // Let's tell libsmtp++ that we want to use ssl // encryption. You need to specify which type // of ssl implementation you would use. If the // smtp server listens on port 25 it will probably // be SMTP::STARTTLS, if the smtp server listens // on port 465 it will most probably be SMTP::SMTPS. // // The second parameter tells libsmtp++ if the certificate // that the smtp server provides for us will be verified // or not. If the certificate will not be verified the // connection is still be encrypted but there is no way // to verify the identity of the server. Possible // Values: // SSLSocket::VERIFY_NONE // SSLSocket::VERIFY_PEER smtp.setSSLOpts ( SMTP::STARTTLS, SSLSocket::VERIFY_NONE ); // Add the message "msg" and the recpients "rcpts" to // the SMTP object. // You can call this method multiple times to add more than // one message that should be sent. smtp.addMessage(msg, rcpts); try { // Finally send the message. This call should everytime // be embedded in a try catch block as any error that // occurs while sending the message will result in // an exception that will be thrown. // All Exceptions thrown by libsmtp++ are inheritated from // the base class Exception. smtp.sendMessage(); } catch(Exception e) { // Exception::what() will provide an informal message about // the error that occured. cout << e.what() << endl; exit(1); } cout << "The message was successfully sent." << endl; exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -