📄 smtp.h
字号:
#ifndef __smtp_h
#define __smtp_h
//============================================================================
// $Header: /shorthand/src/smtp.h 2 8/28/02 6:27a Arm $
//-----------------------------------------------------------------------------
// Author: Andrei Remenchuk <andrei@remenchuk.com>
//-----------------------------------------------------------------------------
// smtp.h: declaration of SMTP client object
//-----------------------------------------------------------------------------
#include <stdarg.h>
/**
* Simple SMTP client
*/
class CSMTPSession {
private:
int socketTimeout; // socket timeout
char* host; // SMTP server host name
int port; // SMTP port
int status; // status of last command
bool needWSACleanup; // true if WSAStartup has been called
int sock; // socket handle
char* localHostName; // name of this host
char* inData; // inbound data buffer
int inLength, inCapacity; // length and capacity of inData
char* errorText; // last error text
int errorCapacity; // capacity of errorText buffer
int responseCode; // last response code
const char* contentType; // content type used for outbound messages
private:
int post(const char* format, ...);
void setError(const char* format, va_list args);
void setError(const char* format, ...);
int wsError(const char* format, ...);
int rejectResponse();
int smtpError();
void ensureInCapacity(int n);
int consume();
const char* getInData();
void flushInData();
const char* getLocalHostName() { return localHostName; }
public:
/**
* Constructs SMTP client for conversation with specified host at
* the given port. No connection is made at this point.
*/
CSMTPSession(const char* host, int port);
int connect();
/**
* Sets value of "Content-Type:" header field for outbound messages.
*/
void setContentType(const char* contentType);
/**
* Sends e-mail message. Connection is automatically closed when
* this function finishes.
*
* parameters:
* from [IN] - message sender
* to [IN] - message recipient(s)
* subject [IN] - message subject
* body [IN] - message body
*
* return value:
* zero if delivery was successfull.
* non-zero error code if delivery failed (getErrorText() provides details).
*/
int sendMessage(const char* from, const char* to, const char* subject, const char* body);
/**
* Returns status of last operation (0=OK).
*/
int getStatus() { return status; }
/**
* Returns error text after failed delivery.
*/
const char* getErrorText();
/**
* Returns last SMTP response code (used internally).
*/
int getResponseCode() { return responseCode; }
int disconnect();
~CSMTPSession();
};
bool getLocalIP(char* ip);
#endif // __smtp_h
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -