📄 example_7.cpp
字号:
#include <libsmtp++/inetsocket.h>#include <libsmtp++/smtp.h>#include <string>// This example shows how to use the logging mechanism// to dump information about what is going on to stdout.// In the next example i will show you how to capture// this messages and process them on your own.//// compile with:// g++ -lsmtp++ example_7.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 ); // Set the verbosity level to VVERBOSE, which // is the most verbose level. Everything will be // logged to stdout. // Possible Levels: // Logger::QUIET // Logger::ERROR // Logger::NORMAL // Logger::VERBOSE // Logger::VVERBOSE smtp.setVerbosity(Logger::VVERBOSE); // 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 + -