//------------------------- CSPMail.h -------------------------

//*************************************************************
//*****       Copyright ©2002 - 2004 Micronovae Ltd       *****
//*****                All rights reserved                *****
//*************************************************************


#ifndef _CSPMAIL
#define _CSPMAIL

#include "CSPConf.h"
#include "CSPLib.h"
#include "CSPString.h"
#include "CSPBuffer.h"
#include "CSPTools.h"
#include "CSPSockets.h"
#include "CSPList.h"
#include <vector>

class CSPTOOLS_CLASS_EXPORT CSPMail : public CSPObject
{
public:
	CSPString To;
	CSPString Cc;
	CSPString Bcc;
	CSPString ReplyAddr;
	CSPString SenderAddr;
	CSPString SenderName;
	CSPString MailServer;
	CSPString Message;
	CSPString Subject;
	CSPString ContentType;
	CSPString Charset;
	
	unsigned short Port;
	unsigned short Priority;


	CSPMail();
	virtual ~CSPMail();
	
	bool Send();
	const CSPString& GetLastErrorStr() const;
	unsigned long GetLastErrorCode() const;
	
protected:
	CSPString strLastError;
	CSPString strLastResponse;
	unsigned long ulTimeout;
	unsigned long ulLastErrorCode;
	unsigned long ulLastRespCode;
	
	unsigned long SendCommand( const CSPString& strCommand, CSPSocket& socMail );
	unsigned long CheckResponse( CSPSocket& socMail );
	void ThrowError();
	void ThrowLastResponse();
	static void MakeEmailList( const CSPString& strRecp, std::vector<CSPString>& vecEmailList );
	static void MakeRecpString( const CSPString& strRecp, CSPString& strList );
};

#endif
