使用socket库发送邮件

当然这样没有登陆验之类的,绝大多数都会把他当成垃圾邮件,或都直接拒收哈。


#coding:utf-8
import socket

host = "163mx00.mxmail.netease.com"
port = 25
param = (host,port)
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(param)
#s.connect((host,port))
data = s.recv(1024)
print(data)

s.send("HELO fromemail.com")
data = s.recv(1024)
print(data)

s.send("mail from:<[email protected]>\n")
data = s.recv(1024)
print(data)

s.send("rcpt to:<[email protected]>\n")
data = s.recv(1024)
print(data)

s.send("data\n")
data = s.recv(1024)
print(data)

s.send("Subject:This is subject title!\r\n\r\nTHis is content!!这个是内容。\r\n\.r\n")
data = s.recv(1024)
print(data)

s.close()

#bye!

最后send内容时有点格式错语。反正网易163报的是:
451 DT:SPM mx15, QcCowEDJXUuGuLFSyCExAg--.1247S2, please try again 1387378930 ht
tp://mail.163.com/help/help_spam_16.htm?ip=183.228.26.22&hostid=mx15&time=138737
8930

使用python3的话有问题,我看了下,需要加编码:

#coding:utf-8
import socket

host = "163mx00.mxmail.netease.com"
port = 25
param = (host,port)
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(param)
#s.connect((host,port))
data = s.recv(1024)
print(data)

s.send(bytes("HELO frommail","utf-8"))
data = s.recv(1024)
print(data)

s.send(bytes("mail from:<[email protected]>\n","utf-8"))
data = s.recv(1024)
print(data)

s.send(bytes("rcpt to:<[email protected]>\n","utf-8"))
data = s.recv(1024)
print(data)

s.send(bytes("data\n","utf-8"))
data=s.recv(1024)
print(data)

s.send(bytes("Subject:This is subject title!\r\n\r\nTHis is content!!这个是内容。\r\n\.r\n","utf-8"))
data = s.recv(1024)
print(data)

s.close()

#bye!




你可能感兴趣的:(使用socket库发送邮件)