📄 example_2.cpp
字号:
#include <libsmtp++/inetsocket.h>#include <libsmtp++/smtp.h>#include <string>// This example shows how to use SMTP Auth with// libsmtp++.// In this case the best SMTP Auth mechanism will// be determined automagically. In the next example// i will show you how to force a specific mechanism.//// compile with:// g++ -lsmtp++ example_2.cpp// the email message that is to be sent.string msg ="To: guojm5@tom.com\n""Subject: test\n""\n""\n""test\n";main(){ // First put all informations together that we might need. string domain = "127.0.0.1"; string from = "guojm582@sohu.com"; string host = "smtp.sohu.com"; string username = "guojm582"; string passwd = "721107"; unsigned int port = 25; // Then group all recipients in a vector. vector<string> rcpts; rcpts.push_back("guojm5@tom.com");// rcpts.push_back("guojm5@tom.com"); // Build the SMTP object. SMTP smtp ( domain, from, host, port ); // Set the username and the password that should // be used for authentication. smtp.setCredentials( username, passwd ); // 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./// for(int i=0;i<100;i++) { 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; sleep(100); } exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -