最近要使用c++发送邮件,而且还需要做一个加解密的工作,poco成了首选。
先从下载
因为不需要使用数据库,--omit排除(不编译的), --prefix安装路径
./configure --omit=Data/ODBC,Data/SQLite --prefix=/usr --static --shared
默认为 shared ,--static 编译静态库
连接时
g++ -I<path-to-poco-include-dir> -o prog prog.cpp -L<path-to-poco-lib-dir> -l<some-poco-lib> -l<another-poco-lib>
例如
g++ -I/usr/local/Poco/include -o prog prog.cpp -L/usr/local/Poco/lib -lPocoFoundation -lPocoNet -lPocoNetSSL -lPocoUtil -lPocoXML
编译Iphone版本
./configure —config=iPhone —static —no-tests —no-samples --omit=Data/ODBC,Data/MySQL
支持
openssl ./configure —config=iPhone —static —no-tests —no-samples --omit=Data/ODBC,Data/MySQL --include-path=[OPENSSL INCLUDE PATH]
打开
poco-1.4.6p2-all/build/config/iPhone,改为
for CC: xcrun -find -sdk iphoneos clang
for CXX: xcrun -find -sdk iphoneos clang++
编译
sudo make IPHONE_SDK_VERSION_MIN=3.0 POCO_TARGET_OSARCH=armv6 -s -j4
make IPHONE_SDK_VERSION_MIN=3.0 POCO_TARGET_OSARCH=armv6 -s -j4
make IPHONE_SDK_VERSION_MIN=3.2 POCO_TARGET_OSARCH=armv7 -s -j4
make IPHONE_SDK_VERSION_MIN=4.3 POCO_TARGET_OSARCH=armv7s -s -j4
make IPHONE_SDK_VERSION_MIN=4.3 POCO_TARGET_OSARCH=arm64 -s -j4
poco 发送邮件的例子
//============================================================================
// Name : testmail.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include
#include
#include
#include
#include
using namespace std;
using namespace Poco::Net;
using namespace Poco;
int main(int argc, char *argv[])
{
string host = "192.168.9.253";
UInt16 port = 25;
string user = "xxx";
string password = "xxx";
string to = "mfc42d@sohu.com";
string from = "test@bingo.com";
string subject = "Your first e-mail message sent using Poco Libraries";
subject = MailMessage::encodeWord(subject, "UTF-8");
string content = "Well done! You've successfully sent your first message using Poco SMTPClientSession";
MailMessage message;
message.setSender(from);
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, to));
message.setSubject(subject);
message.setContentType("text/plain; charset=UTF-8");
message.setContent(content, MailMessage::ENCODING_8BIT);
try {
SMTPClientSession session(host, port);
session.open();
try {
session.login(SMTPClientSession::AUTH_NONE, user, password);
for(int i=0;i<300000;i++)
{
session.sendMessage(message);
}
cout << "Message successfully sent" << endl;
session.close();
} catch (SMTPException &e) {
cerr << e.displayText() << endl;
session.close();
return 0;
}
} catch (NetException &e) {
cerr << e.displayText() << endl;
return 0;
}
return 0;
}
链接命令
阅读(11801) | 评论(1) | 转发(2) |