最近在看有关协议分析的资料,其中谈到了邮件传输协议(SMTP)的工作原理,深受感触。之后在网上又搜索了一些相关的资料,大概的整理了一下,希望对大家有帮助,有不对的地方请批评指正。
Source |
Destiination |
Protocol |
Info |
172.17.1.1 |
192.168.0.1 |
SMTP |
RESPONSE:220 abc.cn ESMTP sendmail 7.14.2/7.14.2; Thu, 22 may 2010 23:30:60 +0800 (CST) |
192.168.0.1 |
172.17.1.1 |
SMTP |
Command: HELO abc.cn |
172.17.1.1 |
192.168.0.1 |
SMTP |
Response: 250 abc.cn Hello [172.17.1.1],pleased to meet you |
192.168.0.1 |
172.17.1.1 |
SMTP |
Command: MAIL FROM: |
172.17.1.1 |
192.168.0.1 |
SMTP |
Response: 250 2.1.0 |
192.168.0.1 |
172.17.0.1 |
SMTP |
Command: RCPT TO: |
172.17.0.1 |
192.168.0.1 |
SMTP |
Response: 250 2.1.0 |
192.168.0.1 |
172.17.0.1 |
SMTP |
Command:DATA |
172.17.0.1 |
192.168.0.1 |
SMTP |
Response: 354 Enter mail,end with “.”on a line by itself |
192.168.0.1 |
172.17.0.1 |
SMTP |
Message Body |
172.17.0.1 |
192.168.0.1 |
SMTP |
Response: 221 2.0.0 ab.cn closing connection |
import smtplib
import email.mime.text
msg = email.mime.text.MIMEText("""
奖学金通知
同学,请速前往
奖学金领取
领取你的奖学金。
""",'html','utf-8')
msg['Subject'] = '奖学金通知'
msg['From'] = u'XX大学' //发送方,可以自己编辑
msg['To'] = '[email protected]'//收件人
try:
smtp = smtplib.SMTP()
smtp.connect('smtp.xx.xx.cn', '25')//smtp服务器链接
smtp.login('***username***','***password***')
smtp.sendmail('***username***',
'[email protected]', msg.as_string())
smtp.quit()
print('Sucess!')
except Exception as e:
print(e)