////////////////////////////////////////////////////////////////////////////////
// Original class CFastSmtp written by
// christopher w. backen <immortal@cox.net>
// More details at: http://www.codeproject.com/KB/IP/zsmtp.aspx
//
// Modifications introduced by Jakub Piwowarczyk:
// 1. name of the class and functions
// 2. new functions added: SendData,ReceiveData and more
// 3. authentication added
// 4. attachments added
// 5 .comments added
// 6. DELAY_IN_MS removed (no delay during sending the message)
// 7. non-blocking mode
// More details at: http://www.codeproject.com/KB/mcpp/CSmtp.aspx
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// SSL/TLS support added by John Tang by making use of OpenSSL: http://www.openssl.org/
// More details at: http://www.codeproject.com/KB/IP/smtp_ssl.aspx
//
// PLAIN, CRAM-MD5 and DIGESTMD5 authentication added by David Johns
//
// Revision History:
// - Version 2.1: Updated with fixes reported as of 26 Mar 2012
// > Fixed issue in main.cpp with referring to USE_TLS in the wrong scope discussed here: http://www.codeproject.com/Messages/4151405/Re-USE_SSL-no-member-of-CSmtp.aspx
// - Thanks to Alan P Brown!
// > Added modifications to allow it to compile in Debian Linux discussed here: http://www.codeproject.com/Messages/4132697/linux-port-patch.aspx
// - Thanks to Oleg Dolgov!
// > Added ability to change the character set, inspired by this post: http://www.codeproject.com/Messages/4238701/Re-The-subject-contains-the-Chinese-letters-could-.aspx
// - Thanks to LeonHuang0726 and John TWC for the suggestion!
// > Added ability to request a read receipt by calling SetReadReceipt as proposed here: http://www.codeproject.com/Messages/3938944/Disposition-Notification-To.aspx
// - Thanks to Gospa for the suggestion!
// > Added check for Linux when adding paths of attachments in the MIME header as suggested here: http://www.codeproject.com/Messages/4357144/portability-bug-w-attachment-name.aspx
// - Thanks to Spike!
// > Switched method of setting private std::string variables to use the = operator as suggested here: http://www.codeproject.com/Messages/4356937/portability-bugs-w-std-string-and-exceptions.aspx
// - Thanks to Spike!
// > Added SetLocalHostName function proposed here: http://www.codeproject.com/Messages/4092347/bug-fixes-GetLocalHostName-Send.aspx
// - Thanks to jerko!
// > Added the modifications to allow it to compile in Linux described here: http://www.codeproject.com/Messages/3878620/My-vote-of-5.aspx
// - Thanks to korisk!
// > Added the fix that corrects behavior when m_sNameFrom is empty described here: http://www.codeproject.com/Messages/4196071/Bug-Mail-sent-by-mail-domain-com.aspx
// - Thanks to agenua.grupoi68!
// - Version 2.0: Updated to all fixes reported as of 23 Jun 2011:
// > Added the m_bAuthenticate member variable to be able to disable authentication
// even though it may be supported by the server. It defaults to true so if it is
// not set the library will act as it would have before the addition.
// > Added the ability to pass the security type, m_type, the new m_Authenticate flag,
// the login and password into the ConnectRemoteServer function. If these new arguments
// are not included in the call the function will work as it did before.
// > Added the ability to pass the new m_Authenticate flag into the SetSMTPServer function.
// If not provided, the function will act as it would before the addition.
// > Added fix described here: http://www.codeproject.com/Messages/3681792/Bug-when-reading-answer.aspx
// - Thanks to Martin Kjallman!
// > Added fixes described here: http://www.codeproject.com/Messages/3707662/Mistakes.aspx
// - Thanks to Karpov Andrey!
// > Added fixes described here: http://www.codeproject.com/Messages/3587166/Re-Possible-Solution-To-Misc-EHLO-Errors.aspx
// - Thanks to Jakub Piwowarczyk!
// - Version 1.9: Started with Revion 6 in code project http://www.codeproject.com/script/Articles/ListVersions.aspx?aid=98355
////////////////////////////////////////////////////////////////////////////////
#include "CSmtp.h"
#include "base64.h"
#include "openssl/err.h"
#include <cassert>
#ifndef LINUX
//Add "openssl-0.9.8l\out32" to Additional Library Directories
#pragma comment(lib, "ssleay32.lib")
#pragma comment(lib, "libeay32.lib")
#endif
Command_Entry command_list[] =
{
{command_INIT, 0, 5*60, 220, ECSmtp::SERVER_NOT_RESPONDING},
{command_EHLO, 5*60, 5*60, 250, ECSmtp::COMMAND_EHLO},
{command_AUTHPLAIN, 5*60, 5*60, 334, ECSmtp::COMMAND_AUTH_PLAIN},
{command_AUTHLOGIN, 5*60, 5*60, 334, ECSmtp::COMMAND_AUTH_LOGIN},
{command_AUTHCRAMMD5, 5*60, 5*60, 334, ECSmtp::COMMAND_AUTH_CRAMMD5},
{command_AUTHDIGESTMD5, 5*60, 5*60, 334, ECSmtp::COMMAND_AUTH_DIGESTMD5},
{command_DIGESTMD5, 5*60, 5*60, 335, ECSmtp::COMMAND_DIGESTMD5},
{command_USER, 5*60, 5*60, 334, ECSmtp::UNDEF_XYZ_RESPONSE},
{command_PASSWORD, 5*60, 5*60, 235, ECSmtp::BAD_LOGIN_PASS},
{command_MAILFROM, 5*60, 5*60, 250, ECSmtp::COMMAND_MAIL_FROM},
{command_RCPTTO, 5*60, 5*60, 250, ECSmtp::COMMAND_RCPT_TO},
{command_DATA, 5*60, 2*60, 354, ECSmtp::COMMAND_DATA},
{command_DATABLOCK, 3*60, 0, 0, ECSmtp::COMMAND_DATABLOCK}, // Here the valid_reply_code is set to zero because there are no replies when sending data blocks
{command_DATAEND, 3*60, 10*60, 250, ECSmtp::MSG_BODY_ERROR},
{command_QUIT, 5*60, 5*60, 221, ECSmtp::COMMAND_QUIT},
{command_STARTTLS, 5*60, 5*60, 220, ECSmtp::COMMAND_EHLO_STARTTLS}
};
Command_Entry* FindCommandEntry(SMTP_COMMAND command)
{
Command_Entry* pEntry = NULL;
for(size_t i = 0; i < sizeof(command_list)/sizeof(command_list[0]); ++i)
{
if(command_list[i].command == command)
{
pEntry = &command_list[i];
break;
}
}
assert(pEntry != NULL);
return pEntry;
}
// A simple string match
bool IsKeywordSupported(const char* response, const char* keyword)
{
assert(response != NULL && keyword != NULL);
if(response == NULL || keyword == NULL)
return false;
int res_len = strlen(response);
int key_len = strlen(keyword);
if(res_len < key_len)
return false;
int pos = 0;
for(; pos < res_len - key_len + 1; ++pos)
{
if(_strnicmp(keyword, response+pos, key_len) == 0)
{
if(pos > 0 &&
(response[pos - 1] == '-' ||
response[pos - 1] == ' ' ||
response[pos - 1] == '='))
{
if(pos+key_len < res_len)
{
if(response[pos+key_len] == ' ' ||
response[pos+key_len] == '=')
{
return true;
}
else if(pos+key_len+1 < res_len)
{
if(response[pos+key_len] == '\r' &&
response[pos+key_len+1] == '\n')
{
return true;
}
}
}
}
}
}
return false;
}
unsigned char* CharToUnsignedChar(const char *strIn)
{
unsigned char *strOut;
unsigned long length,
i;
length = strlen(strIn);
strOut = new unsigned char[length+1];
if(!strOut) return NULL;
for(i=0; i<length; i++) strOut[i] = (unsigned char) strIn[i];
strOut[length]='\0';
return strOut;
}
////////////////////////////////////////////////////////////////////////////////
// NAME: CSmtp
// DESCRIPTION: Constructor of CSmtp class.
// ARGUMENTS: none
// USES GLOBAL: none
// MODIFIES GL: m_iXPriority, m_iSMTPSrvPort, RecvBuf, SendBuf
// RETURNS: none
// AUTHOR: Jakub Piwowarczyk
// AUTHOR/DATE: JP 2010-01-28
// JP 2010-07-08
////////////////////////////////////////////////////////////////////////////////
CSmtp:
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
CSmtp_v2_1_ssl.zip (81个子文件)
CSmtp_v2_1_ssl
base64.h 190B
CSmtp.sln 874B
openssl-0.9.8l
inc32
openssl
aes.h 6KB
stack.h 4KB
rand.h 6KB
des.h 10KB
symhacks.h 20KB
tls1.h 19KB
ssl.h 82KB
ui_compat.h 3KB
ssl2.h 10KB
dh.h 8KB
rc2.h 4KB
x509v3.h 29KB
asn1.h 48KB
ssl3.h 22KB
comp.h 2KB
tmdiff.h 4KB
md2.h 4KB
pem.h 28KB
ossl_typ.h 7KB
ec.h 21KB
rsa.h 19KB
krb5_asn.h 7KB
ripemd.h 4KB
hmac.h 4KB
bn.h 33KB
bio.h 30KB
des_old.h 18KB
sha.h 7KB
md4.h 5KB
safestack.h 139KB
ecdh.h 5KB
err.h 13KB
e_os2.h 9KB
dso.h 16KB
kssl.h 6KB
evp.h 38KB
engine.h 38KB
ui.h 16KB
idea.h 4KB
ecdsa.h 10KB
txt_db.h 4KB
pq_compat.h 6KB
md5.h 5KB
pem2.h 3KB
crypto.h 24KB
cast.h 4KB
pqueue.h 3KB
ssl23.h 4KB
blowfish.h 5KB
dsa.h 11KB
conf_api.h 4KB
ebcdic.h 540B
buffer.h 4KB
objects.h 33KB
opensslv.h 4KB
asn1t.h 27KB
x509.h 47KB
conf.h 9KB
lhash.h 7KB
asn1_mac.h 19KB
pkcs12.h 12KB
rc4.h 4KB
pkcs7.h 16KB
obj_mac.h 125KB
x509_vfy.h 20KB
opensslconf.h 7KB
dtls1.h 6KB
store.h 26KB
ocsp.h 24KB
out32
ssleay32.lib 677KB
libeay32.lib 3.79MB
CSmtp.vcproj 6KB
md5.h 4KB
CSmtp.cpp 70KB
Article Source.htm 9KB
main.cpp 2KB
CSmtp.h 7KB
base64.cpp 4KB
md5.cpp 13KB
共 81 条
- 1
天堂大鸟
- 粉丝: 10
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页