下载本节例子程序和源代码 (9.67 KB) |
Socket连接后,按 ESMTP 协议通讯(注意每条命令结尾符“回车/换行/./回车/换行”结束): 1、EHLO <Domain>/r/n 这条命令可以不要,但是按照标准的写法,还是加上好。 Example: EHLO smtp.163.net/r/n 2、AUTH LOGIN/r/n 告诉服务器,要进行验证了。 3、Base64_Username/r/n 发送经过 Base64 编码的用户名给服务器。 4、Base64_Password/r/n 发送经过 Base64 编码的密码给服务器。 5、MAIL FROM: /r/n 发送者的Email地址。 Example: MAIL FROM: [email protected]/r/n 6、RCPT TO: /r/n 目标Email地址。 Example: RCPT TO: [email protected]/r/n 7、DATA/r/n 开始传送数据。 8、发送数据/r/n./r/n 注意:SMTP协议只发送信息,至于如何区分CC、BCC、Subject、Body等不属于SMTP的范围,详情请查看RFC文档MAIL格式部分 简单说一下MAIL格式:Sunject:<主题>/r/n/r/n<内容>,还有好多…… 返回值为“250 ***”表示正常,同时***里含有MessageID等信息(前面的命令都有相应的返回信息) 9、QUIT/r/n Over,走人…… |
"EHLO smtp.163.net", 13, 10 "AUTH LOGIN", 13, 10 "lcother", 13, 10 "lcother_password", 13, 10 "MAIL FROM:[email protected]", 13, 10 "RCPT TO:[email protected]", 13, 10 "DATA", 13, 10 "From: 老罗", 13, 10,/ "To: Somebody", 13, 10, / "Subject: 你好吗?", 13, 10, 0 "MIME-Version: 1.0", 13, 10, / "X-Mailer: LCMailer by LC", 13, 10, / "Content-type:multipart/mixed;Boundary=www.LuoCong.com", 13, 10, 13, 10, / "--www.LuoCong.com", 13, 10, / "Content-type:text/plain;Charset=GB2312", 13, 10, / "Content-Transfer-Encoding:8bit", 13, 10, 13, 10, / "好久不见,最近过得好吗?(正文内容)", 13, 10, 13, 10, 0, / .if (有附件) "--www.luocong.com", 13, 10, / .while (files to be sent) 13, 10, / 13, 10, / "--", 13, 10, / "Content-Type:application/octet-stream;Name=文件名", 0, / "Content-Disposition:attachment;FileName=文件名", 0, / 13, 10, / "Content-Transfer-Encoding:Base64", 13, 10, 13, 10, 0, / 经过 Base64 编码的文件内容, 13, 10, 0/ .endw .endif 13, 10, / "--www.luocong.com--", / 13, 10, ".", 13, 10 "QUIT", 13, 10 |