SMTP encapsulation of Simple Mail transmission protocol

Source: Internet
Author: User

 

 

On the Internet, Email is the most popular transmission media. This article includes two Protocols:. POP 3 Protocol: POP3 protocol (postal transfer protocol), which means receiving mails from the Email server. I have submitted a class that encapsulates the POP3 protocol. For official descriptions of this agreement, refer to RFC1225. SMTP protocol: SMTP (Simple Mail Transfer Protocol) refers to the mail sent to its destination. For details about the SMTP protocol, refer to RCF 821. My new contribution is to encapsulate the SMTP protocol. I cannot fully implement the SMTP protocol, but you can use it to send emails in many applications. This class has several methods. The method name is the same as the SMTP command, so it is easy to understand. In this class, I once again used CSocket as a class member, so I can use it in the thread. below is the class encoding and comment:

 

//////////////////////////////////////// //////////////////////////////

// SMTP. h: interface for the CSMTP class.

//

//////////////////////////////////////// //////////////////////////////

 

# If! Defined (afx_smtp_h1_617f7e82_7f4d_11d1_88a0_1_1c3025811_encoded _)

# Define afx_smtp_h1_617f7e82_7f4d_11d1_88a0_1_1c3025811_encoded _

 

# If _ MSC_VER> = 1000

# Pragma once

# Endif // _ MSC_VER >=1000

 

# Define CONNECTION_CHECK 0

# Define HELLO_CHECK 1

# Define MAIL_CHECK 2

# Define RCPT_CHECK 3

# Define DATA_START_CHECK 4

# Define DATA_END_CHECK 5

# Define QUIT_CHECK 6

# Define DATA_CHECK 7

 

 

Class CSMTP

{

Public:

BOOL Mail ();//

CString GetErrorMessage ();

BOOL Data (CString Subject, CString Body );

CString GetTo ();

BOOL SetTo (CString );

CString GetFrom ();

Void SetFrom (CString from );

BOOL Mail (CString from );

BOOL Disconnect ();

CString GetHost ();

Void SetHost (CString Host );

BOOL Connect (CString Host, CString Me );

BOOL Connect ();

CSMTP ();

Virtual ~ CSMTP ();

Private:

CString GetError (CString Response );

CString m_ErrorMessage;

BOOL CheckResponse (int Type );

Int m_NoOfTo;

CStringArray m_To;

CString m_From;

CSocket m_SMTPServer;

CString m_Host;

};

 

# Endif //! Defined (afx_smtp_h1_617f7e82_7f4d_11d1_88a0_1_1c3025811_encoded _)

 

 

//////////////////////////////////////// //////////////////////////////////

// SMTP. cpp: implementation of the CSMTP class.

//

//////////////////////////////////////// //////////////////////////////

 

# Include "stdafx. h"

# Include "MailSend. h"

# Include "SMTP. h"

 

# Ifdef _ DEBUG

# Undef THIS_FILE

Static char THIS_FILE [] =__ FILE __;

# Define new DEBUG_NEW

# Endif

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.