• hm_nie
    了解作者
  • C/C++
    开发工具
  • 21.6MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 25
    下载次数
  • 2017-09-05 10:00
    上传日期
使用C++ 发送邮箱,支持163,126(已测)。QQ邮箱理论上也支持
C++ SMTP发送邮件.zip
  • MailSendC++
  • TestEMal
  • Debug
  • vc100.idb
    779KB
  • CL.write.1.tlog
    1.2KB
  • CL.read.1.tlog
    57.3KB
  • mt.read.1.tlog
    286B
  • TestEMal.write.1.tlog
    0B
  • rc.write.1.tlog
    266B
  • TestEMal.vcxprojResolveAssemblyReference.cache
    713B
  • base64.obj
    103.4KB
  • rc.read.1.tlog
    258B
  • link.6612.read.1.tlog
    2B
  • link.6612-cvtres.write.1.tlog
    2B
  • mt.command.1.tlog
    372B
  • cl.command.1.tlog
    1.8KB
  • link.6612.write.1.tlog
    2B
  • link-cvtres.read.1.tlog
    2B
  • link.6612-cvtres.read.1.tlog
    2B
  • TestEMal.exe.intermediate.manifest
    381B
  • main.obj
    57.6KB
  • link.7904-cvtres.write.1.tlog
    2B
  • TestEMal_manifest.rc
    206B
  • CSmtp.obj
    562.7KB
  • link.write.1.tlog
    840B
  • TestEMal.exe.embed.manifest.res
    472B
  • link-cvtres.write.1.tlog
    2B
  • link.7904.write.1.tlog
    2B
  • link.command.1.tlog
    1.6KB
  • TestEMal.lastbuildstate
    50B
  • rc.command.1.tlog
    502B
  • link.read.1.tlog
    3.4KB
  • mt.write.1.tlog
    286B
  • TestEMal.exe.embed.manifest
    406B
  • link.7904.read.1.tlog
    2B
  • link.7904-cvtres.read.1.tlog
    2B
  • TestEMal.log
    37.4KB
  • vc100.pdb
    340KB
  • base64.h
    190B
  • CSmtp.cpp
    24.8KB
  • TestEMal.vcxproj.user
    143B
  • CSmtp.h
    3.7KB
  • main.cpp
    2KB
  • TestEMal.vcxproj
    4KB
  • TestEMal.vcxproj.filters
    1.3KB
  • base64.cpp
    3.8KB
  • ipch
  • testemal-7f0652
  • testemal-e51ab50b.ipch
    52MB
  • Debug
  • TestEMal.ilk
    1.6MB
  • TestEMal.pdb
    1.5MB
  • TestEMal.exe
    137KB
  • TestEMal.sdf
    28.8MB
  • TestEMal.sln
    891B
  • TestEMal.suo
    14.5KB
内容介绍
////////////////////////////////////////////////////////////////////// // Original class CFastSmtp written by // christopher w. backen <immortal@cox.net> // More details at: http://www.codeproject.com/KB/IP/zsmtp.aspx // // Modifications: // 1. name of the class and some functions // 2. new functions added: SendData,ReceiveData and more // 3. authentication added // 4. attachments added // introduced by Jakub Piwowarczyk <podsaski@gmail.com> // More details at: http://www.codeproject.com/KB/mcpp/CSmtp.aspx ////////////////////////////////////////////////////////////////////// #include "CSmtp.h" #pragma warning(push) #pragma warning(disable:4786) ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CSmtp::CSmtp() { // Initialize variables m_oError = CSMTP_NO_ERROR; m_iXPriority = XPRIORITY_NORMAL; m_iSMTPSrvPort = 25; m_pcLocalHostName = NULL; m_pcMailFrom = NULL; m_pcNameFrom = NULL; m_pcSubject = NULL; m_pcMsgBody = NULL; m_pcXMailer = NULL; m_pcReplyTo = NULL; m_pcLogin = NULL; m_pcPassword = NULL; m_pcSMTPSrvName = NULL; if((RecvBuf = new char[BUFFER_SIZE]) == NULL) { m_oError = CSMTP_LACK_OF_MEMORY; return; } if((SendBuf = new char[BUFFER_SIZE]) == NULL) { m_oError = CSMTP_LACK_OF_MEMORY; return; } // Initialize WinSock WORD wVer = MAKEWORD(2,2); if (WSAStartup(wVer,&wsaData) != NO_ERROR) { m_oError = CSMTP_WSA_STARTUP; return; } if (LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 ) { m_oError = CSMTP_WSA_VER; WSACleanup(); return; } } CSmtp::~CSmtp() { // Clear vectors Recipients.clear(); CCRecipients.clear(); BCCRecipients.clear(); Attachments.clear(); // Free memory if (m_pcLocalHostName) delete[] m_pcLocalHostName; if (m_pcMailFrom) delete[] m_pcMailFrom; if (m_pcNameFrom) delete[] m_pcNameFrom; if (m_pcSubject) delete[] m_pcSubject; if (m_pcMsgBody) delete[] m_pcMsgBody; if (m_pcXMailer) delete[] m_pcXMailer; if (m_pcReplyTo) delete[] m_pcReplyTo; if (m_pcLogin) delete[] m_pcLogin; if (m_pcPassword) delete[] m_pcPassword; if(SendBuf) delete[] SendBuf; if(RecvBuf) delete[] RecvBuf; // Cleanup WSACleanup(); } ////////////////////////////////////////////////////////////////////// // Methods ////////////////////////////////////////////////////////////////////// bool CSmtp::AddAttachment(const char *path) { std::string str(path); Attachments.insert(Attachments.end(),str); return true; } bool CSmtp::AddRecipient(const char *email, const char *name) { assert(email); if(!email) { m_oError = CSMTP_UNDEF_RECIPENT_MAIL; return false; } Recipent recipent; recipent.Mail.insert(0,email); name!=NULL ? recipent.Name.insert(0,name) : recipent.Name.insert(0,""); Recipients.insert(Recipients.end(), recipent); return true; } bool CSmtp::AddCCRecipient(const char *email, const char *name) { assert(email); if(!email) { m_oError = CSMTP_UNDEF_RECIPENT_MAIL; return false; } Recipent recipent; recipent.Mail.insert(0,email); name!=NULL ? recipent.Name.insert(0,name) : recipent.Name.insert(0,""); CCRecipients.insert(CCRecipients.end(), recipent); return true; } bool CSmtp::AddBCCRecipient(const char *email, const char *name) { assert(email); if(!email) { m_oError = CSMTP_UNDEF_RECIPENT_MAIL; return false; } Recipent recipent; recipent.Mail.insert(0,email); name!=NULL ? recipent.Name.insert(0,name) : recipent.Name.insert(0,""); BCCRecipients.insert(BCCRecipients.end(), recipent); return true; } bool CSmtp::Send() { unsigned int i,rcpt_count,res,FileId; char *FileBuf = NULL, *FileName = NULL; FILE* hFile = NULL; unsigned long int FileSize,TotalSize,MsgPart; // ***** CONNECTING TO SMTP SERVER ***** assert(m_pcSMTPSrvName); // connecting to remote host: if( (hSocket = ConnectRemoteServer(m_pcSMTPSrvName, m_iSMTPSrvPort)) == INVALID_SOCKET ) { m_oError = CSMTP_WSA_INVALID_SOCKET; printf("Unable to send the mail1111...\n"); return false; } Sleep(DELAY_IN_MS); if(!ReceiveData()) return false; switch(SmtpXYZdigits()) { case 220: break; default: m_oError = CSMTP_SERVER_NOT_READY; return false; } // EHLO <SP> <domain> <CRLF> sprintf(SendBuf,"EHLO %s\r\n",GetLocalHostName()!=NULL ? m_pcLocalHostName : "domain"); if(!SendData()) return false; Sleep(DELAY_IN_MS); if(!ReceiveData()) return false; switch(SmtpXYZdigits()) { case 250: break; default: m_oError = CSMTP_COMMAND_EHLO; return false; } // AUTH <SP> LOGIN <CRLF> strcpy(SendBuf,"AUTH LOGIN\r\n"); if(!SendData()) return false; Sleep(DELAY_IN_MS); if(!ReceiveData()) return false; switch(SmtpXYZdigits()) { case 334: break; default: m_oError = CSMTP_COMMAND_AUTH_LOGIN; return false; } // send login: if(!m_pcLogin) { m_oError = CSMTP_UNDEF_LOGIN; return false; } std::string encoded_login = base64_encode(reinterpret_cast<const unsigned char*>(m_pcLogin),strlen(m_pcLogin)); sprintf(SendBuf,"%s\r\n",encoded_login.c_str()); if(!SendData()) return false; Sleep(DELAY_IN_MS); if(!ReceiveData()) return false; switch(SmtpXYZdigits()) { case 334: break; default: m_oError = CSMTP_UNDEF_XYZ_RESPOMSE; return false; } // send password: if(!m_pcPassword) { m_oError = CSMTP_UNDEF_PASSWORD; return false; } std::string encoded_password = base64_encode(reinterpret_cast<const unsigned char*>(m_pcPassword),strlen(m_pcPassword)); sprintf(SendBuf,"%s\r\n",encoded_password.c_str()); if(!SendData()) return false; Sleep(DELAY_IN_MS); if(!ReceiveData()) return false; switch(SmtpXYZdigits()) { case 235: break; case 535: m_oError = CSMTP_BAD_LOGIN_PASS; return false; default: m_oError = CSMTP_UNDEF_XYZ_RESPOMSE; return false; } // ***** SENDING E-MAIL ***** // MAIL <SP> FROM:<reverse-path> <CRLF> if(m_pcMailFrom == NULL) { m_oError = CSMTP_UNDEF_MAILFROM; return false; } sprintf(SendBuf,"MAIL FROM:<%s>\r\n",m_pcMailFrom); if(!SendData()) return false; Sleep(DELAY_IN_MS); if(!ReceiveData()) return false; switch(SmtpXYZdigits()) { case 250: break; default: m_oError = CSMTP_COMMAND_MAIL_FROM; return false; } // RCPT <SP> TO:<forward-path> <CRLF> rcpt_count = Recipients.size(); for(i=0;i<Recipients.size();i++) { sprintf(SendBuf,"RCPT TO:<%s>\r\n",(Recipients.at(i).Mail).c_str()); if(!SendData()) return false; Sleep(DELAY_IN_MS); if(!ReceiveData()) return false; switch(SmtpXYZdigits()) { case 250: break; default: m_oError = CSMTP_COMMAND_RCPT_TO; rcpt_count--; } } if(!rcpt_count) return false; for(i=0;i<CCRecipients.size();i++) { sprintf(SendBuf,"RCPT TO:<%s>\r\n",(CCRecipients.at(i).Mail).c_str()); if(!SendData()) return false; Sleep(DELAY_IN_MS); if(!ReceiveData()) return false; } for(i=0;i<BCCRecipients.size();i++) { sprintf(SendBuf,"RCPT TO:<%s>\r\n",(BCCRecipients.at(i).Mail).c_str()); if(!SendData()) return false; Sleep(DELAY_IN_MS); if(!ReceiveData()) return false; } // DATA <CRLF> strcpy(SendBuf,"DATA\r\n"); if(!SendData()) return false; Sleep(DELAY_IN_MS); if(!ReceiveData()) return false; switch(SmtpXYZdigits()) { case 354: break; default: m_oError = CSMTP_COMMAND_DATA; return false; } // send header(s) if(!FormatHeader(SendBuf)) { m_oError = CSMTP_UNDEF_MSG_HEADER; return false; } if(!SendData()) return false; // send text message sprintf(SendB
评论
    相关推荐
    • VC简单的SMTP邮件服务器程序
      内容索引:VC/C++源码,网络相关,SMTP,邮件服务器 VC简单的SMTP邮件服务器程序,确实简单,实现的功能也是基本的,设置好邮件服务器地址、用户名、密码、端口以及防火墙设置等参数,它就开始运行了,当作初学者的一个...
    • SMTP邮件服务器MailSlurper.zip
      MailSlurper 是一个便携的 SMTP 邮件服务器,对本地和团队应用开发来说非常有用。MailSlurper 体积小运行快速,支持 SQLite, MSSQL 和 MySQL. 数据库。 标签:MailSlurper
    • SMTP邮件发送
      用c#写的smTP方式的邮件发送程序
    • PHP通过SMTP实现发送邮件
      这个是PHP通过SMTP发送邮件类,很好用的。配置好邮件服务器的相关信息,即可成功发送邮件。已经通过测试,可以试下。
    • smtp发送邮件
      Java Mail是由Sun定义的一套收发电子邮件的API,不同的厂商可以提供自己的实现类。
    • linuxC邮件群发SMTP
      linux C写的邮件群发工具。 亲测可以使用。用公司邮箱向外发了10000封邮件smtp群发。
    • C语言socket/smtp发送邮件,支持附件,支持windows和linux
      /* * 使用规则: * 可以发送带附件的邮件,附件大小限制由发送方服务器而定,暂未测试具体为多少MB ...* 自动解析发件箱的SMTP服务器 */ 支持windows系统,linux系统。 上一版本的更新版。 详细情况件压缩包的readme
    • C#smtp邮件发送
      简单的C#邮件发送程序,只能用163的邮箱发送。
    • C# SMTP 发送邮件
      C# SMTP 发送邮件 测试了:163邮件,Gmail邮件,Hotmail邮件
    • libiconv-1.1.tar.gz
      字符集转换程序