A recent project needs to use SMTP to send mail, the previous library class does not exist, do not like to install pear or use Pear's net/smtp class, it is too complicated. The core is extracted directly from the Discuz and slightly modified.
From the Protocol analysis Web, find the commands and answers to the SMTP protocol, and the SMTP protocol's session between sending SMTP and receiving SMTP is done by sending SMTP commands and receiving SMTP feedback responses. The commonly used commands are as follows:
Hello <domain> <CRLF> Identifies the sender to a Hello command to receive SMTP
MAIL from: <reverse-path> <CRLF> <reverse-path> is the sender address. This command tells the receiver the beginning of a new mail delivery and initializes all States and buffers. This command begins a message transfer process that ultimately completes the delivery of the message data to one or more mailboxes.
RCPT to: <forward-path> <CRLF> <forward-path> Identify the addresses of individual message recipients
DATA <CRLF>
Receiving SMTP will treat the behavior that follows as mail data to <CRLF>. <CRLF> to identify the end of the data.
REST <CRLF> exit/Reset the current message transfer
NOOP <CRLF> requires the receive SMTP to do only the OK answer. (For testing)
QUIT <CRLF> requires that receive SMTP return an OK answer and turn off the transmission.
VRFY <string> <CRLF> verifies that the specified mailbox exists, and because of security factors, the server suppresses this command more than once.
EXPN <string> <CRLF> verifies that a given mailbox list exists, and that expanding the list of mailboxes is often prohibited.
Help <CRLF> What command does the query server support?
Note: The <CRLF> returns, wraps, and ASCII codes are 13, 10 (decimal), respectively.
Alternatively, you can use Telnet for simple manual use of SMTP under command.
Like what:
Telnet smtp.263.net 25
Trying 211.150.96.25 ...
Connected to Smtp.263.net.
Escape character is ' ^] '.
Welcome to Coremail System (with anti-spam) 2.1 for 263 (040326)
HELO weiqiong@cctk.net
Smtp.263.net
Mail from:weiqiong@cctk.net
Ok
RCPT To:g2_t1@263.net
Ok
Data
354 End data with <CR><LF>.<CR><LF>
haha
.
Ok:queued as b9e452ff3e
Quit
221 Bye
Connection closed by foreign host.
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.