SmtpSendManger.h
上传用户:weimei12
上传日期:2022-08-11
资源大小:185k
文件大小:5k
- #pragma once
- /********************************************************************
- created: 2008:9:26 13:40
- author: 李欣
- filename: c:MyProjectSimpleMailSimpleMailSmtpSendManger.h
- classname: CSendManger
- purpose: implement the smtp protocol to send the mail
- *********************************************************************/
- class CSmtpSendManger
- {
- public:
- CSmtpSendManger(void);
- public:
- ~CSmtpSendManger(void);
- ///<summary>
- /// send the mail
- ///</summary>
- HRESULT SendMailMessage(IN const CString& strRcs,
- IN const CString& strCCRcs,
- IN const CString& strBCCRcs,
- IN const CString& strSubject,
- IN const CString& strContent,
- IN const CStringArray& strAttachFiles);
- ///<summary>
- /// set the user name
- ///</summary>
- void SetUserName(IN const CString& strUserName);
- ///<summary>
- /// set the password
- ///</summary>
- void SetPassword(IN const CString& strPassword);
- ///<summary>
- /// set the smtp server address
- ///</summary>
- void SetSmtpServer(IN const CString& strSmtpServer);
- ///<summary>
- /// set the sender address
- ///</summary>
- void SetSendMail(IN const CString& strSendMail);
- ///<summary>
- /// set whether to validate the identity
- ///</summary>
- void SetValidate(IN BOOL bValidate);
- ///<summary>
- /// get the last error description
- ///</summary>
- CString GetLastErrorMsg();
- private:
- ///<summary>
- /// basic network functions
- ///</summary>
- BOOL Connect();
- BOOL Disconnect();
- //******************************************************************************
- ///<summary>
- /// SMTP commands
- ///</summary>
- ///<summary>
- /// identify the sender to the receiver
- ///</summary>
- ///<param name = nType>
- /// the type of the protocol
- ///</param>
- BOOL CmdHelo(IN int nType = ORIGIN_SMTP);
- ///<summary>
- /// initiate a mail transaction
- ///</summary>
- BOOL CmdMailFrom();
- ///<summary>
- /// identify the recipient
- ///</summary>
- BOOL CmdRcptTo(IN const CString& strTo);
- ///<summary>
- /// transmit data
- ///</summary>
- BOOL CmdData(IN CMailMessage* pMsg);
- ///<summary>
- /// confirm a user
- ///</summary>
- BOOL CmdVrfy(IN const CString& str);
- ///<summary>
- /// confirm a mailing list
- ///</summary>
- BOOL CmdExpn(IN const CString& strList);
- ///<summary>
- /// ask the receiver to send helpful information
- ///</summary>
- ///<param name = strCmdList>
- /// the command that the server supports
- ///</param>
- BOOL CmdHelp(OUT vector<CString>& strCmdList);
- ///<summary>
- /// no action other than that the receiver send an OK reply
- ///</summary>
- BOOL CmdNoop();
- ///<summary>
- /// close the transmission
- ///</summary>
- BOOL CmdQuit();
- ///<summary>
- /// cancel the current transaction
- ///</summary>
- BOOL CmdRSET();
- ///<summary>
- /// verify the username and its password
- ///</summary>
- BOOL CmdAuthLogin();
- //******************************************************************************
- ///<summary>
- /// add multiple recipients
- ///</summary>
- BOOL AddMultiRecipient(IN CMailMessage* pMsg);
- ///<summary>
- /// set socket parameters
- ///</summary>
- BOOL SetNetParams();
- ///<summary>
- /// get the response and parse
- ///</summary>
- ///<param name = >
- /// the responset type that you want to check
- ///</param>
- BOOL CheckResponse(IN const UINT nResponse_expected);
- ///<summary>
- /// handle the periods in the message body
- ///</summary>
- CString CookBody(IN CMailMessage* pMsg);
- //******************************************************************************
- ///<summary>
- /// the mail server address
- ///</summary>
- CString m_strSmtpServer;
- ///<summary>
- /// the sender address
- ///</summary>
- CString m_strSendMail;
- ///<summary>
- /// the name and password
- ///</summary>
- CString m_strUserName;
- CString m_strPassword;
- ///<summary>
- /// whether the smtp server need validate the identity
- ///</summary>
- BOOL m_bValidate;
- ///<summary>
- /// the socket used for transmitting
- ///</summary>
- CSocket m_wsSMTPServer;
- ///<summary>
- /// the last error
- ///</summary>
- CString m_strError;
- ///<summary>
- /// the socket parameters
- ///</summary>
- int m_nRecvTimeout;
- int m_nSendTimeout;
- ///<summary>
- /// the pointer to the buffer for receiving
- ///</summary>
- TCHAR *m_pszResponse_buf;
- ///<summary>
- /// used for responding
- ///</summary>
- struct response_code
- {
- UINT nResponse; // Response expected
- TCHAR* pszMessage; // Error message if we don't get it
- };
- enum eResponse
- {
- GENERIC_SUCCESS = 0,
- CONNECT_SUCCESS,
- DATA_SUCCESS,
- QUIT_SUCCESS,
- AUTH_LOGIN,
- LOGIN_SUCCESS,
- LOGIN_FAILED,
- // Include any others here
- LAST_RESPONSE // Do not add entries past this one
- };
- static response_code s_response_table[];
- };