Click here to Skip to main content
15,896,330 members
Articles / Desktop Programming / MFC

CSmtpProxyMT 1.0

Rate me:
Please Sign up or sign in to vote.
4.93/5 (34 votes)
15 Nov 2001CPOL4 min read 131.5K   1.6K   38  
An SMTP proxy class with ability to insert signatures to outgoing mails. Does not require MFC.
#include <winsock2.h>
#include <process.h>

#define OK_SUCCESS 0
#define ERR_RUNNING 1
#define ERR_WSAFAIL 2
#define ERR_INVALIDSOCKET 3
#define ERR_BIND 4
#define ERR_LISTEN 5
#define ERR_HOST 6
#define ERR_CONNECT 7
#define ERR_STOPPED 8


class CSmtpProxyMT  
{
private:
	struct SSmtp
	{
		char SmtpServer[250];
		char ClientIP[20];
		int SmtpPort;
		int LocalPort;
		SOCKET LocalSocket;
		CSmtpProxyMT* pCSmtpProxyMT;
	public:
		void CopyStruct(SSmtp *pSSmtp);
	};
	struct socket_pair
	{
		SOCKET src;
		SOCKET dest;
		BOOL IsClient;
		CSmtpProxyMT* pCSmtpProxyMT;
	};

protected:
	BOOL AcceptFlag;
	SSmtp m_SSmtp;
	SOCKET SmtpServerSocket;	
	char ProxySignature[2048];	

public:
	int StopProxy();
	int StartProxy(char *server, int port, int localport);		
	CSmtpProxyMT();
	virtual ~CSmtpProxyMT();
	BOOL SetSignature(char *sig);
	
private:	
	static void AddToEnd(char* buff, char* b, char* sig);
	static int InsertTextSignature(char*,char*);
	static BOOL FoundBoundary(char *boundary, char *buff);
	static BOOL IsEndOfData(char*);
	static char * MakeUpper(char * );
	static BOOL IsDataCommand(char *);
	DWORD SmtpProxyThreadMain();
	static DWORD SmtpProxyThread(DWORD arg);
	void StartProxyThread(CSmtpProxyMT* m_pCSmtpProxyMT);
	static DWORD SmtpClientThread(DWORD arg);
	void StartClientThread(SSmtp *pSSmtp);
	static DWORD SmtpDataThread(DWORD arg);
	static void StartDataThread(socket_pair *pspair);
	
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
Nish Nishant is a technology enthusiast from Columbus, Ohio. He has over 20 years of software industry experience in various roles including Chief Technology Officer, Senior Solution Architect, Lead Software Architect, Principal Software Engineer, and Engineering/Architecture Team Leader. Nish is a 14-time recipient of the Microsoft Visual C++ MVP Award.

Nish authored C++/CLI in Action for Manning Publications in 2005, and co-authored Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on CodeProject.com and another 250+ blog articles on his WordPress blog. Nish is experienced in technology leadership, solution architecture, software architecture, cloud development (AWS and Azure), REST services, software engineering best practices, CI/CD, mentoring, and directing all stages of software development.

Nish's Technology Blog : voidnish.wordpress.com

Comments and Discussions