⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example_8.cpp

📁 LINUX下发送邮件的库,测试很好用,有各种发送测试的例子
💻 CPP
字号:
#include <libsmtp++/inetsocket.h>#include <libsmtp++/smtp.h>#include <string>// This example shows how to use the logging mechanism// to gather information about what is going on by specifying// a callback function.//// compile with:// g++ -lsmtp++ example_8.cpp// the email message that is to be sent.string msg ="To: t_benk@web.de\n""Subject: test\n""\n""\n""test\n";// This is the callback function that// will be called whenever libsmtp++ provides// a message for you.void callback(string str, int level){	// The level can be used to filter the log messages	// on your own. However, only messages which a level	// that is lesser or equal the level set with 	// Logger::setVerbosity() will be reach this method	// (of course).	// So, to catch all log messages set the log level	// to Logger::VVERBOSE.	switch (level)	{		case Logger::NORMAL:			cout << "[NORMAL]   : " << str;			break;		case Logger::ERROR:			cout << "[ERROR]    : " << str;			break;		case Logger::VERBOSE:			cout << "[VERBOSE]  : " << str;			break;		case Logger::VVERBOSE:			cout << "[VVERBOSE] : " << str;			break;	}}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.	// Possible Levels:	// Logger::QUIET	// Logger::ERROR	// Logger::NORMAL	// Logger::VERBOSE	// Logger::VVERBOSE	smtp.setVerbosity(Logger::VVERBOSE);	// Set the callback function libsmtp++ should use	// to log messages.	smtp.setCallBackFunction(callback);	// 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 + -