接收邮件的,暂时没搞定,不过在SF上找到了这个发送邮件的库文件.它提供了一个比较完整的类,可以简单的调用发送邮件.下面是作者提供的一个例子,不过由于连SMTP发邮件需要密码,所以代码我改了一下.
// This file is part of the jwSMTP library. 
// 
//    jwSMTP library is free software; you can redistribute it and/or modify 
//    it under the terms of the GNU General Public License as published by 
//    the Free Software Foundation; either version 2 of the License, or 
//    (at your option) any later version. 
// 
//    jwSMTP library is distributed in the hope that it will be useful, 
//    but WITHOUT ANY WARRANTY; without even the implied warranty of 
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the 
//    GNU General Public License for more details. 
// 
//    You should have received a copy of the GNU General Public License 
//    along with jwSMTP library; if not, write to the Free Software 
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA    02111-1307    USA 
// 
//      http://johnwiggins.net 
//      smtplib@johnwiggins.net 
// 
// http://www.boost.org 
//#include <boost\thread\thread.hpp> 
 
#include <iostream> 
#include “jwsmtp/jwsmtp.h” 
 
using std::cout; 
using std::cin; 
using std::string; 
 
void Usage() { 
   cout << “jwSMTP library demo program\n” 
           “maildemo <email toaddress> <email fromaddress> <smtpserver>\n” 
           “   e.g.\n” 
           “      maildemo recipient@there.com me@server.com mail.server.com\n”; 

 
int main(int argc, char* argv[]) 

   if(argc != 4) { 
      Usage(); 
      return 0; 
   } 
 
   cout << “jwSMTP library demo program\n\n”; 
   string to(argv[1]); 
   string from(argv[2]); 
   string smtpserver(argv[3]); 
 
   if(to.length() < 2 || from.length() < 2 || smtpserver.length() < 2) { 
      Usage(); 
      return 0; 
   } 
 
   char str[2048]; 
   cout << “Please enter the subject of the mail\n”; 
   cin.getline(str, 500);     
   string subject(str); 
   strcpy(str, “”); 
 
   cout << “Please enter the message body end with \”.\” on a line by itself\n”; 
   string mailmessage; 
   while(true) { 
      cin.getline(str, 2048); 
      if(!strcmp(str, “.”)) 
         break; 
         
      mailmessage += str; 
      mailmessage += “\r\n”; 
      strcpy(str, “”); 
   } 
 
   cout << “\nPlease wait sending mail\n”; 
   // This is how to tell the mailer class that we are using a direct smtp server 
   // preventing the code from doing an MX lookup on ’smtpserver’ i.e. passing 
   // false as the last parameter. 
   jwsmtp::mailer mail(to.c_str(), from.c_str(), subject.c_str(), mailmessage.c_str(), 
                       smtpserver.c_str(), jwsmtp::mailer::SMTP_PORT, false); 
 
   mail.username(“suei8423@163.com”); 
   mail.password(“###”); 
   // using a local file as opposed to a full path. 
   mail.attach(“/root/Desktop/223901.jpg”); 
 
   // add another recipient (carbon copy) 
   //mail.addrecipient(“someoneelse@somewhere.net”, mailer::Cc); 
 
   // set a new smtp server! This is the same as setting a nameserver. 
   // this depends on the constructor call. i.e. in the constructor 
   // If MXLookup is true this is a nameserver 
   // If MXLookup is false this is an smtp server 
   //mail.setserver(“mail.somewherefun.com”); 
   // same again except using an IP address instead. 
   //mail.setserver(“192.168.0.1″); 
 
   // boost::thread thrd(mail); 
   // thrd.join(); // optional 
   // or:- 
 
   // Use authentication 
   //mail.username(“testuser”); 
   //mail.password(“secret”); 
   // LOGIN authentication by default 
   // if you want plain as opposed to login authentication 
   //mail.authtype(jwsmtp::mailer::PLAIN); 
       
   mail.operator()(); 
   cout << mail.response() << “\n\n”; 
 
   //mail.reset(); // now we can mail someone else. 
   //mail.setmessage(“flibbletooting”); 
   //mail.setsubject(“another message same object”); 
   //mail.attach(“/home/user1/image.gif”); 
   // or a win example 
   //mail.attach(“C:\\image.gif”); 
   //mail.addrecipient(“someoneelseagain@foobar.net”); 
 
   //mail.operator ()(); 
   //cout << mail.response() << “\n”; 
   return 0; 
}

作者提供的库要自己编译一次.
在编译例子程序时,WINDOWS的例子可以直接编译,在LINUX下要用类似下面的命令
g++ demo2.cpp -o demo2 -I/usr/local/include/jwsmtp-1.32 /usr/local/lib/libjwsmtp.a

一个发送邮件的C++库–jwsmtp的更多相关文章

  1. 如何持续集成/交付一个开源.NET函数库到Nuget.org

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:这是一个简单的入门向导,涉及到GitHub.AppVeyor和Nuget.org. 最 ...

  2. Javascript的一个生产PDF的库: unicode和中文问题的解决

    Javascript的一个生产PDF的库: unicode和中文问题的解决基于canvas和jspdf库, 实现用javascript的支持中文pdf生成实用工具.参考:http://javascri ...

  3. C 封装一个简单二叉树基库

    引文 今天分享一个喜欢佩服的伟人,应该算人类文明极大突破者.收藏过一张纸币类型如下 那我们继续科普一段关于他的简介 '高斯有些孤傲,但令人惊奇的是,他春风得意地度过了中产阶级的一生,而  没有遭受到冷 ...

  4. 一个现代化的JSON库Moshi针对Android和Java

    Moshi 是一个现代化的JSON库针对Android和Java.它可以很容易地解析JSON成Java对象: String json = ...; Moshi moshi = new Moshi.Bu ...

  5. JQuery是继prototype之后又一个优秀的Javascript库

    JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Oper ...

  6. 一个发送邮件的java类,包含多种发送方法

    import java.util.Calendar;import java.util.Date; import java.util.Properties; import javax.mail.Addr ...

  7. 介绍一个python视频处理库:moviepy

    由于博客园的插件和我自己博客的插件不一致,代码以及视频插入转换很麻烦,所以还是我原来博客的地址查看吧. 介绍一个python视频处理库:moviepy

  8. android一个下拉放大库bug的解决过程及思考

    android一个下拉放大库bug的解决过程及思考 起因 项目中要做一个下拉缩放图片的效果,搜索了下github上面,找到了两个方案. https://github.com/Frank-Zhu/Pul ...

  9. 一个交互式可视化Python库——Bokeh

    本篇为<Python数据可视化实战>第十篇文章,我们一起学习一个交互式可视化Python库--Bokeh. Bokeh基础 Bokeh是一个专门针对Web浏览器的呈现功能的交互式可视化Py ...

随机推荐

  1. 获取CPU序列号

    public string GetCPUSerialNo() { string cpuSerialNo = string.Empty; ManagementClass managementClass ...

  2. JAVA多态学习3

    这一节我们来学习抽象类 抽象类–深入讨论 抽象类是java中一个比較重要的类. 1.用abstract关键字来修饰一个类时.这个类就是抽象类. 2.用abstract关键字来修饰一个方法时,这种方法就 ...

  3. cocos2d-x的经历(含源码——)

    源于手游的火爆和大环境的影响,最近在学习cocos2d-x.其实以前一直有想搞andriod和ios的尝试,可惜本屌丝没钱买mac os x,只好先开始学习andriod,于是买了小米2s作为测试机, ...

  4. WinForm - ListView点击空白事件

    有时看似很小的一个问题却可能困扰我们许久,比如ListView这个问题,其Click事件只是在有选中项的时候才触发,点击其空白处(无选中项)是不会触发Click事件的,找了许久才终于找到解决这个问题的 ...

  5. Python标准库:内置函数dict(**kwarg)

    本函数是从一个字典參数构造一个新字典.參数kwarg是键值对的字典參数.以两个*开头的參数.就会收集成字典形式. 样例: #dict() #以键对方式构造字典 d1 = dict(one = 1, t ...

  6. Atitit.dwr3 不能显示错误具体信息的解决方式,控件显示错误具体信息的解决方式 java .net php

    Atitit.dwr3 不能显示错误具体信息的解决方式,控件显示错误具体信息的解决方式 java .net php 1. Keyword/subtitle 1 2. 使用dwr3的异常convert处 ...

  7. 如何解决android logcat不打印信息在android开发中

    用eclipse进行android开发中经常遇到logcat无任何信息输出,这给我们调试程序带来很大的不便.解决办法:window-->show view-->选择android下的dev ...

  8. Windows Azure入门教学系列 (三):创建第一个Worker Role程序

    在开始本教学之前,请确保你从Windows Azure 平台下载下载并安装了最新的Windows Azure开发工具.本教学使用Visual Studio 2010作为开发工具. 步骤一:创建解决方案 ...

  9. DBA 应该要注意Linux 环境下的一些操作

    DBA 对OS的依赖.一丁点儿也不亚于DB.对于Oracle DBA.尤为突出     DB和OS的感情也与日俱增.耦合度高的让人一度以为这两要劳燕双飞了 例如.Oracle里面. 而且.故障诊断以及 ...

  10. Decoding BASE64 in ABAP

    Code Gallery Decoding BASE64 in ABAP Skip to end of metadata Created by Frank Klausner, last modifie ...