import base64
import re
import socketmsg = "\r\n I love computer networks!"
endmsg = "\r\n.\r\n"
# TAG: 服务器地址
# Choose a mail server (e.g. Google mail server) and call it mailserver
mailserver = 'smtp.163.com'  # Fill in start   #Fill in end
port = 25
ssl_port = 994
# mailserver_ip = socket.gethostbyname(mailserver)
from_man = 'xxx@163.com'
from_man_pwd = 'xxx'  # 授权码,不是密码
recv_man = 'xxx@qq.com'login_id = base64.b64encode(from_man.encode()).decode() + '\r\n'
login_pwd = base64.b64encode(from_man_pwd.encode()).decode() + '\r\n'# TAG: 建立连接
# Create socket called clientSocket and establish a TCP connection with mailserver
#Fill in start
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientSocket.connect((mailserver, port))
print('connect成功')#Fill in end
recv0 = clientSocket.recv(1024).decode()
print(recv0)
if recv0[:3] != '220':print('[1]220 reply not received from server.')# TAG: 1.HELLO
# Send HELO command and print server response.
heloCommand = 'HELO Alice\r\n'
clientSocket.send(heloCommand.encode())
recv1 = clientSocket.recv(1024).decode()
print(recv1)
if recv1[:3] != '250':print('250 reply not received from server.')# TAG: 登录
log_command = 'AUTH LOGIN\r\n'
clientSocket.send(log_command.encode())
recv = clientSocket.recv(1024).decode()
print(recv)
if (recv[:3] != '334'):print('334 login wrong')clientSocket.send(login_id.encode())
recv = clientSocket.recv(1024).decode()
print(recv)
if recv[:3] == '535':print('Login ID wrong')clientSocket.send(login_pwd.encode())
recv = clientSocket.recv(1024).decode()
print(recv)
if recv[:3] == '535':print('Password wrong')# # TAG: TLS加密
# temp='STARTTLS\r\n'
# print(temp)
# clientSocket.send(temp.encode())
# recv = clientSocket.recv(1024).decode()
# print(recv)# TAG: 2.MAIL FROM
# Send MAIL FROM command and print server response.
# Fill in start
mailfrom = 'MAIL FROM: <' + from_man + '>\r\n'
clientSocket.send(mailfrom.encode())
recv2 = clientSocket.recv(1024).decode()
print(recv2)
if recv2[:3] != '250':print('250 reply not received from server.')
# Fill in end# TAG: 3.RCPT TO
# Send RCPT TO command and print server response.
# Fill in start
rcptto = 'RCPT TO: <' + recv_man + '>\r\n'
clientSocket.send(rcptto.encode())
recv3 = clientSocket.recv(1024).decode()
print(recv3)
if recv3[:3] != '250':print('250 reply not received from server.')
# Fill in end# TAG: 4.DATA
# Send DATA command and print server response.
# Fill in start
data = 'DATA\r\n'
clientSocket.send(data.encode())
recv4 = clientSocket.recv(1024).decode()
print(recv4)
if recv4[:3] != '354':print('354 reply not received from server.')
# Fill in end# TAG: 5.Send message
# Send message data.
# Fill in start
send = "From: " + from_man + '\r\n'
send += "To: " + recv_man + '\r\n'
send += "Subject: " + "First Web Mail Test From Love6" + '\r\n'
send += msg
clientSocket.send(send.encode())
# Fill in end# Message ends with a single period.
# Fill in start
clientSocket.send(endmsg.encode())
recv5 = clientSocket.recv(1024).decode()
print(recv5)
if recv5[:3] != '250':print('250 reply not received from server.')
# Fill in end# TAG: 6.QUIT
# Send QUIT command and get server response.
# Fill in start
quit = 'QUIT\r\n'
clientSocket.send(quit.encode())
recv6 = clientSocket.recv(1024).decode()
print(recv6)
if recv6[:3] != '221':print('221 reply not received from server.')
# Fill in endclientSocket.close()

SMTP客户端python实现相关推荐

  1. python flask热更新_客户端python热更新

    介绍: 热更新,就是在维持服务不间断的情况下,对软件代码逻辑或配置数据进行更新修复.随着游戏项目引入了脚本语言以后,热更新技术逐渐成为了标配,在我经历过的游戏项目中,无论是服务端还是客户端,版本的更新 ...

  2. 客户端python热更新

    介绍: 热更新,就是在维持服务不间断的情况下,对软件代码逻辑或配置数据进行更新修复.随着游戏项目引入了脚本语言以后,热更新技术逐渐成为了标配,在我经历过的游戏项目中,无论是服务端还是客户端,版本的更新 ...

  3. SMTP 客户端 msmtp mutt

    SMTP 客户端 msmtp mutt ubuntu msmtp mutt 设置 mutt 设置 msmtp 发送邮件 tls 参考 ubuntu # cat /etc/issue Ubuntu 18 ...

  4. python客户端和服务端实验_结合服务器和客户端python

    我正在尝试使用python(稍后可能用c语言)和TCP套接字制作一个本地网络聊天程序. 我的目的是让服务器监听当前计算机的地址以获取传入消息,并将这些消息转发给客户端(我现在还不确定). 客户端将是一 ...

  5. linux与python客户端,Python编写的socket服务器和客户端

    服务器端: #!/usr/bin/python import socket host='127.0.0.1' port=8123 s=socket.socket(socket.AF_INET,sock ...

  6. 怎么设置域名SRV记录实现IMAP/SMTP客户端自动配置

    本文就是一个很技巧性的技术性的配置,讲的是通过设置域名SRV记录,实现邮件客户端自动配置.这里的自动配置是什么意思呢?就是当你打开OUTLOOK.Windows自带的"邮件"客户端 ...

  7. Thrift的服务器和客户端Python案例

    服务器 Thrift提供的常见服务端类型有一下几种: thrift.server.TServer.TSimpleServer 单线程服务器 thrift.server.TServer.TThreade ...

  8. wind客户端python接口 java调用

    之前公司业务部门提出需要做wind 新债数据对比,原本做的方案是 直接 从数据中心wind库中获取,但是数据中心wind库,并非实时数据而是 每半个小时由wind 主动推送的数据,业务觉得不满足要求, ...

  9. python 管理windows客户端_scrapyd的Windows管理客户端|python基础教程|python入门|python教程...

    https://www.xin3721.com/eschool/pythonxin3721/ ScrapydManage GitHub地址:https://github.com/kanadebliss ...

最新文章

  1. .Net 2.0 新功能:迭代器(Iterators)
  2. 使用DatagramSocket发送、接收数据(Socket之UDP套接字)
  3. 在myeclipse中建立maven项目
  4. SpringBoot 中 @RequestBody的正确使用方法
  5. MFC六大核心机制之一:MFC程序的初始化
  6. 【effective c++读书笔记】【第8章】定制new和delete(2)
  7. 解决使用Servlet输出乱码问题(一行代码解决一切)
  8. 点击按钮打开选择文件对话框
  9. GIT : IDEA切换到某个tag
  10. 【Java】@transient代表着什么
  11. 数据治理注意哪些问题
  12. 微型计算机断电后信息将会丢失,2011年计算机基础知识精选部分及答案三
  13. 全国英语等级考试网上报名
  14. 中数据库url怎么写_WIN10下怎么找到MYSQL数据库中存储数据的位置
  15. require smarty.class.php 报错,Smarty SSTI
  16. 大学抢课到学校的计算机房,网络选课制度引发“抢课大战”
  17. 完全删除conime.exe 程序。。。
  18. MEMORY系列之“DRAM概述”
  19. 梦殇 chapter four
  20. codelite 设置

热门文章

  1. 淘宝买零件组装一台手机,可以正常使用,想自己组装手机的可以看下
  2. Linux系统连接校园网指南(JLU)
  3. 如何制作注册登录网址
  4. 【原型模式】原型模式深入分析
  5. Golang 二叉树遍历
  6. 20194311姜晨昊Exp2-后门原理与实践
  7. 前端面试题:讲一下jQuery
  8. 【分享】光纤光缆PPT
  9. 发送邮件(用代码模拟邮箱服务器发送邮件)
  10. Android IBinder的linkToDeath介绍