64,649
社区成员
发帖
与我相关
我的任务
分享
/*--------------------------------------------------------------
* File : SendMail.h
* Author : libo QQ:16645709
* Date : 2008.6.14--2009.11
* Vesion : V 01.00.009
* Comment : 一个smtp邮件发送类
* Function: can send attachments, can distinguish show straight matter or text in 163
* History: 修改了显示进度不正确的问题
* 2008.11.12: 修改显示发送进度的函数名SMailSendProgress,
* 2008.12.01: 增加显示连接,发送命令,发送内容等信息的函数
* 2009.09.18: 修改发送协议,减少了与服务器的认证时间
* 2009.09.18: 增加发送HTML文件的能力
* 2009.09.18: 增加显示实时信息和显示发送进度的回调函数
*------------------------------------------------------------*/
#if !defined __SENDMAIL_H__
#define __SENDMAIL_H__
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifdef WIN32
#include <windows.h>
#endif
#include <sys/stat.h>
#include <time.h>
#include <iostream>
#include <vector>
#include ".\\communicate\\communicate.h"//网络通信类
using namespace std;
typedef void (*SMailInfoPtr)(const char* apInfo);// 实时信息回调
typedef void (*SMailProPtr)(const int& aiProgress, const int& aiTotalSize);//进度显示回调
class CSendMail //协议类
{
public:
CSendMail();
virtual ~CSendMail();
bool SendData(const char *apName, const char* apFromAddr, const char* apPassword, const char* apSubject, const char* apContent, const char* apHtml= NULL);
bool SendData(const char *apName, const char* apServer, const char* apUser, const char* apPassword, const char* apFromAddr, const char* apSubject, const char* apContent, const char* apHtml= NULL);
int AddAttachment(const char *apFile);//添加附件
int AddReceive(const char* apToAddr);//添加收件人
char *GetErrMsg(); //获取错误信息
void SetBcc(); //密送
void SetSSL(); //SSL连接
void SetSmtpPort(const int &aiPort); //port
void SetInfoCallBack(SMailInfoPtr aMailPtr);//实时信息回调函数设置,传入方式
void SetProgCallBack(SMailProPtr aMailPro);//进度大小回调函数设置
private:
/************************************************************************/
/* brief: connect the mail server
/* param mailServer: Mail server name that is domain name not ip*/
/************************************************************************/
int ConnectServer(const char* apMailServer);
/************************************************************************/
/* brief: send the content
/* param: content pointer*/
/************************************************************************/
void SendContent(const char *apDataContent, const char *apHtmlContent = NULL);
/************************************************************************/
/* brief: send the attachment
/* param filename: file name*/
/************************************************************************/
bool SendAffix(const char *apFilename);
bool SendContentFile(const char *apFilename, const int&aiContentID);
/************************************************************************/
/* brief: send the basic information
/* param Name: Name which is the name of send mail
/* param username: mail address name, such as xxxx, which is login name of xxxx@163.com
/* param password: mail password
/* param fromaddr: send the mail name , for example xxxx@163.com */
/* param toaddr: receive the mail address
/* param subject: the subject of the mail
/************************************************************************/
bool SendCMD(const char *apName, const char*apUserName, const char*apPassword, const char* apFromaddr, const char*apSubject);
/************************************************************************/
/* brief: quit from the mail server */
/************************************************************************/
bool SendQuit();
/************************************************************************/
/* brief: get response from server after sent data */
/************************************************************************/
bool GetResponse(const char* apKey = NULL);
int CloseSocket(const int aiSocket);
virtual void SMailSendProgress(const int aiProgress, const int aiTotalSize);//进度信息回调函数设置,虚函数方式
virtual void SMailInfo(const char* apInfo)//实时信息回调函数设置,虚函数方式
{
}
void CheckContentFile(const char* apContent);
inline int ANSIToBase64(const char *szInANSI, int nInLen, char *szOutBase64, int nOutLen);
void RandString(char* apRandStr, const int&aiSize);
protected:
int ciSocket;
int ciPort;
int ciRet;
int ciTotalSize;
int ciCurPro;
char csRecv_data[1024];
char csFilename[1024];
char *cpSend_data;
char csBoundaryStart[64];
char csBoundaryEnd[64];
bool cbBcc;
vector<string>AttFile;
vector<string>cvReceive;
vector<string>cvContentFile;
vector<string>cvContentID;
SMailInfoPtr cSIptr;
SMailProPtr cProPtr;
Communicate *ccomptr;
};
#endif