使用python socket实现smtp协议,出现了神奇的问题
from socket import *
import base64
msg = "\r\n I Love Computer Networks!" #Declarations
endmsg="\r\n.\r\n"
mailfrom = "MAIL FROM:<l847238926@163.com>\r\n"
rcptto="RCPT TO:<754845950@qq.com>\r\n"
data = "DATA\r\n"
quitmsg="QUIT\r\n"
#Choose a mail server (e.g. Google mail server) and call it mailserver
mailserver="smtp.163.com" #Use the local Host as SMTP Server
mailPort=25 #Specify Port For Local SMTP
connectaddress=(mailserver,mailPort)
#Create socket called clientsocket and establish a TCP connection with mailserver
clientSocket=socket(AF_INET,SOCK_STREAM) #Assign IP address and port number
clientSocket.connect(connectaddress) #Connect to Local SMTP
recv=clientSocket.recv(1024)
print(recv)
if recv[:3].decode()!='220': #Print Error Clause
print("220 reply not received from server")
#Send HELO command and print server response.
heloCommand="HELO Alice\r\n"
clientSocket.send(bytes(heloCommand.encode()))
recv1=clientSocket.recv(1024)
print(recv1.decode())
if recv1.decode()[:3]!="250":
print("250 reply not received from server.")
print('-----------------------------------')
loginini = b'AUTH LOGIN\r\n'
userCommand = base64.b64encode(b'18390242095@163.com\r\n')
passwordCommand = base64.b64encode(b'xudoudou3661615\r\n')
clientSocket.send(loginini)
recv2 = clientSocket.recv(1024).decode('utf-8')
print('222+ ',recv2)
clientSocket.send(userCommand)
recv3 = clientSocket.recv(1024).decode('utf-8')
print('333+ ',recv3)
clientSocket.send(passwordCommand)
recv4 = clientSocket.recv(1024).decode('utf-8')
print('444+ ',recv4)
print('-----------------------------------')
#Send MAIL FROM command and print server response.
clientSocket.send(bytes(mailfrom.encode())) #send mail, had to convert to bytes
check=clientSocket.recv(1024)
print(check) #print confirmation of working messages
#Send RCPT TO command and print server response.
clientSocket.send(bytes(rcptto.encode())) #recieve, had to convert to bytes
check1=clientSocket.recv(1024)
print(check1) #print confirmation of working messages
#Send DATA command and print server response.
clientSocket.send(bytes(data.encode())) #DATA, had to convert to bytes
check2=clientSocket.recv(1024)
print(check2) #print confirmation of working messages
#Message ends with a single period.
clientSocket.send(bytes((mailfrom+msg+endmsg).encode())) #Concatinate bits for message
check3=clientSocket.recv(1024)
print(check3) #print confirmation of working messages
#Send QUIT command and get server response.
clientSocket.send(bytes(quitmsg.encode())) #Quit the session
check4=clientSocket.recv(1024)
print(check4) 相关推荐
国央企创新负责人如何构建面向核心技术攻关的多维创新资源协同机制?.docx
国央企创新负责人如何构建面向核心技术攻关的多维创新资源协同机制?
科技中介服务机构如何提升技术对接服务的专业性与效率?.docx
科技中介服务机构如何提升技术对接服务的专业性与效率?
政府科技管理者在推动区域科技成果转化时,如何提升科技成果与产业需求的对接精准度?.docx
政府科技管理者在推动区域科技成果转化时,如何提升科技成果与产业需求的对接精准度?
科技中介服务机构在为企业提供技术对接服务时,如何提升全流程服务的智能化水平?.docx
科技中介服务机构在为企业提供技术对接服务时,如何提升全流程服务的智能化水平?
无功优化基于多目标差分进化算法的含DG配电网无功优化模型【IEEE33节点】(Matlab代码实现)
内容概要:本文研究了基于多目标差分进化算法的含分布式电源(DG)配电网无功优化模型,以IEEE33节点系统为仿真平台,旨在应对DG接入后引发的电压波动加剧与网络损耗上升等关键问题。通过构建综合考虑有功网损最小化、电压偏差最小化等多重目标的优化模型,并融入节点电压、支路电流及无功补偿容量等多种运行约束,采用多目标差分进化算法(MODE)进行高效求解,实现了对无功补偿设备出力与DG无功调节能力的协同优化。文中系统阐述了算法的数学原理、模型的构建逻辑及详细的仿真设置,并通过与其他优化方法的对比分析,充分验证了所提方案在提升电压质量、降低网络损耗及增强系统运行经济性与稳定性方面的优越性。; 适合人群:具备电力系统分析、优化理论及Matlab编程基础,从事配电网运行控制、分布式能源并网技术、智能电网优化调度等相关领域的科研人员、工程技术人员及高年级研究生。; 使用场景及目标:①应用于高比例DG渗透的现代配电网无功电压优化调度,有效提升系统运行的安全性与经济性;②为相关领域研究人员提供一套完整的、基于多目标进化算法解决复杂电力系统多目标优化问题的Matlab代码实现范例,便于直接复现、验证与二次开发;③作为高校相关课程的教学案例,用于演示先进优化算法在电力系统中的具体应用。; 阅读建议:建议读者结合文中详尽的理论推导与提供的Matlab代码,仔细复现仿真结果,深入理解多目标优化问题的建模思路、Pareto最优解集的概念以及差分进化算法在处理复杂约束条件下的具体实现技巧,并可尝试将该模型拓展至其他标准测试系统或引入更多的优化目标与约束条件以进行深入研究。


