⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smtp.h

📁 这里实现了用smtp来发送email
💻 H
字号:
// SMTP.h: interface for the CSMTP class.
// Copyright (c) 1998, Wes Clyburn
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SMTP_H__55DE48CB_BEA4_11D1_870E_444553540000__INCLUDED_)
#define AFX_SMTP_H__55DE48CB_BEA4_11D1_870E_444553540000__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include <afxsock.h>
#include "MailMessage.h"

#define SMTP_PORT 25		
#define RESPONSE_BUFFER_SIZE 1024

class CSMTP  
{
public:
	//构造函数,输入SMTP服务器地址、端口(25)
	CSMTP( LPCTSTR szSMTPServerName, UINT nPort = SMTP_PORT );
	virtual ~CSMTP();
	//设置服务器地址、端口
	void SetServerProperties( LPCTSTR szSMTPServerName, UINT nPort = SMTP_PORT );
	CString GetLastError();
	UINT GetPort();
	//断开
	BOOL Disconnect();
	//连接服务器
	BOOL Connect();
	//格式化邮件信息
	virtual BOOL FormatMailMessage( CMailMessage* msg );
	//发送信息
	BOOL SendMessage( CMailMessage* msg );
	CString GetServerHostName();
	//终止发送
	void Cancel(); 
	
private:
	//获取服务器的响应
	BOOL get_response( UINT response_expected );
	//由于邮件正文结束需要以 回车.回车 表明,
	//因此需要将中间部分的这样的字符删除
	CString cook_body( CMailMessage* msg );
	
	CString m_sError;
	BOOL m_bConnected;
	UINT m_nPort;
	CString m_sSMTPServerHostName;
	//负责连接SMTP
	CSocket m_wsSMTPServer;
	
protected:
	//发送消息
	virtual BOOL transmit_message( CMailMessage* msg );
	//响应信息结构
	struct response_code
	{
		//响应数字(250等)
		UINT nResponse;	
		//字符串信息
		TCHAR* sMessage;	
	};
	
	enum eResponse
	{
		GENERIC_SUCCESS = 0,
			CONNECT_SUCCESS,
			DATA_SUCCESS,
			QUIT_SUCCESS,
			LAST_RESPONSE	
	};
	TCHAR *response_buf;
	static response_code response_table[];
};

#endif // !defined(AFX_SMTP_H__55DE48CB_BEA4_11D1_870E_444553540000__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -