POCO开源库发送邮件(局域网内)示例
来源:互联网 发布:mac的照片文件夹 编辑:程序博客网 时间:2024/06/06 19:40
#include <iostream>#include "Poco/Logger.h"#include "Poco/FormattingChannel.h"#include "Poco/PatternFormatter.h"#include "Poco/FileChannel.h"#include "Poco/Message.h"#include "Poco/Net/MailMessage.h"#include "Poco/Net/MailRecipient.h"#include "Poco/Net/SMTPClientSession.h"#include "Poco/Net/StringPartSource.h"#include "Poco/Path.h"#include "Poco/Exception.h"using Poco::Logger;using Poco::PatternFormatter;using Poco::FormattingChannel;using Poco::FileChannel;using Poco::Message;using Poco::Net::MailMessage;using Poco::Net::MailRecipient;using Poco::Net::SMTPClientSession;using Poco::Net::StringPartSource;using Poco::Path;using Poco::Exception;#pragma comment(lib,"PocoFoundationd.lib")#pragma comment(lib,"PocoNetd.lib")const unsigned char PocoLogo[] = {#include "PocoLogo.hpp"//图片的二进制文件,保存为.hpp格式};#define FILE_NAME "main.cpp"//命令参数:sendMail.exe 192.180.10.208 xxx@spinfosec.com xxx@spinfosec.comint main(int argc, char **argv){FormattingChannel *pFCFile = NULL;pFCFile = new FormattingChannel(new PatternFormatter("%Y-%m-%d %H:%M:%S.%c %U %u %N[%P]:%s:%q:%t"));pFCFile->setChannel(new FileChannel("./sample.log"));pFCFile->open();Logger &fileLogger = Logger::create("FileLogger", pFCFile, Message::PRIO_DEBUG);if (4 != argc){Path p(argv[0]);fileLogger.error("usage:",FILE_NAME,49);fileLogger.error(p.getBaseName(),FILE_NAME,50);fileLogger.error("Send an email greeting from <sender> to <recipient>,using the SMTP server at <mailhost>.",FILE_NAME,51);return -1;}std::string mailHost(argv[1]);std::string sender(argv[2]);std::string recipient(argv[3]);fileLogger.debug(mailHost,FILE_NAME,61);fileLogger.debug(sender,FILE_NAME,62);fileLogger.debug(recipient,FILE_NAME,63);try{MailMessage message;message.setSender(sender);message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, recipient));message.setSubject("Hello from the POCO C++ Libraries");std::string content;content += "Hello ";content += recipient;content += ",\r\n\r\n";content += "This is a greeting from the POCO C++ Libraries.\r\n\r\n";std::string logo(reinterpret_cast<const char*>(PocoLogo), sizeof(PocoLogo));message.addContent(new StringPartSource(content));message.addAttachment("logo", new StringPartSource(logo, "image/gif"));SMTPClientSession session(mailHost);session.open();session.login();session.sendMessage(message);session.close();}catch (Exception& exc){fileLogger.error(exc.displayText(),FILE_NAME,88);return 1;}pFCFile->close();return 0;}
0 0
- POCO开源库发送邮件(局域网内)示例
- 使用JavaMail通过SMTP协议发送局域网(内网)邮件
- 邮件发送--局域网中配置James邮件服务器(二)
- App内邮件发送
- 邮件发送示例代码
- PHP发送邮件示例
- C# 发送邮件示例
- 邮件发送示例
- yii2 - 邮件发送-示例
- python发送邮件示例
- 邮件发送代码示例
- libcurl 邮件发送示例
- python发送邮件示例
- java发送邮件示例
- ubuntu中redmine局域网内发送邮件提示redmine getaddrinfo: Name or service not known
- 社内邮件自动发送
- seam发送邮件email示例
- javamail发送邮件简单示例
- linux下c程序 daemon、fork与创建pthread的顺序问题
- 指针的指针与二维数组
- Java异常处理
- Python高级特性(1)
- Android TabHost菜单放在底部方法
- POCO开源库发送邮件(局域网内)示例
- ORACLE 多表关联 UPDATE 语句
- 算法导论 第23章 广度优先搜索 深度优先搜索 拓扑排序 强连通分量 C++实现
- pycassaShell用法备忘录
- 在Spring基础上实现自己的异常处理框架
- linux ---2014.6.25
- Python高级特性(1)
- Linux下USB驱动框架分析
- Mysql初始化root密码和允许远程访问