SMTP客户端python实现
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实现相关推荐
- python flask热更新_客户端python热更新
介绍: 热更新,就是在维持服务不间断的情况下,对软件代码逻辑或配置数据进行更新修复.随着游戏项目引入了脚本语言以后,热更新技术逐渐成为了标配,在我经历过的游戏项目中,无论是服务端还是客户端,版本的更新 ...
- 客户端python热更新
介绍: 热更新,就是在维持服务不间断的情况下,对软件代码逻辑或配置数据进行更新修复.随着游戏项目引入了脚本语言以后,热更新技术逐渐成为了标配,在我经历过的游戏项目中,无论是服务端还是客户端,版本的更新 ...
- SMTP 客户端 msmtp mutt
SMTP 客户端 msmtp mutt ubuntu msmtp mutt 设置 mutt 设置 msmtp 发送邮件 tls 参考 ubuntu # cat /etc/issue Ubuntu 18 ...
- python客户端和服务端实验_结合服务器和客户端python
我正在尝试使用python(稍后可能用c语言)和TCP套接字制作一个本地网络聊天程序. 我的目的是让服务器监听当前计算机的地址以获取传入消息,并将这些消息转发给客户端(我现在还不确定). 客户端将是一 ...
- linux与python客户端,Python编写的socket服务器和客户端
服务器端: #!/usr/bin/python import socket host='127.0.0.1' port=8123 s=socket.socket(socket.AF_INET,sock ...
- 怎么设置域名SRV记录实现IMAP/SMTP客户端自动配置
本文就是一个很技巧性的技术性的配置,讲的是通过设置域名SRV记录,实现邮件客户端自动配置.这里的自动配置是什么意思呢?就是当你打开OUTLOOK.Windows自带的"邮件"客户端 ...
- Thrift的服务器和客户端Python案例
服务器 Thrift提供的常见服务端类型有一下几种: thrift.server.TServer.TSimpleServer 单线程服务器 thrift.server.TServer.TThreade ...
- wind客户端python接口 java调用
之前公司业务部门提出需要做wind 新债数据对比,原本做的方案是 直接 从数据中心wind库中获取,但是数据中心wind库,并非实时数据而是 每半个小时由wind 主动推送的数据,业务觉得不满足要求, ...
- python 管理windows客户端_scrapyd的Windows管理客户端|python基础教程|python入门|python教程...
https://www.xin3721.com/eschool/pythonxin3721/ ScrapydManage GitHub地址:https://github.com/kanadebliss ...
最新文章
- .Net 2.0 新功能:迭代器(Iterators)
- 使用DatagramSocket发送、接收数据(Socket之UDP套接字)
- 在myeclipse中建立maven项目
- SpringBoot 中 @RequestBody的正确使用方法
- MFC六大核心机制之一:MFC程序的初始化
- 【effective c++读书笔记】【第8章】定制new和delete(2)
- 解决使用Servlet输出乱码问题(一行代码解决一切)
- 点击按钮打开选择文件对话框
- GIT : IDEA切换到某个tag
- 【Java】@transient代表着什么
- 数据治理注意哪些问题
- 微型计算机断电后信息将会丢失,2011年计算机基础知识精选部分及答案三
- 全国英语等级考试网上报名
- 中数据库url怎么写_WIN10下怎么找到MYSQL数据库中存储数据的位置
- require smarty.class.php 报错,Smarty SSTI
- 大学抢课到学校的计算机房,网络选课制度引发“抢课大战”
- 完全删除conime.exe 程序。。。
- MEMORY系列之“DRAM概述”
- 梦殇 chapter four
- codelite 设置