def data(self,
msg):
"""
SMTP 'DATA' command -- sends message data to server.
Automatically quotes lines beginning with a period per rfc821.
Raises SMTPDataError if there is an unexpected reply to the
DATA command; the return value from this method is the final
response code received when the all data is sent.
msg: Message in a string buffer or a filename referring to
a file containin the data to be send (string).
Returns: Tuple with the status code + a message from the SMTP
host (tuple/integer, string).
"""
self.putcmd("data")
(code, repl) = self.getreply()
if self.debuglevel >0 : print "data:", (code, repl)
if code != 354:
raise smtplib.SMTPDataError(code, repl)
else:
if (not self.__msgInFile):
# Data contained in the message in memory.
q = smtplib.quotedata(msg)
if q[-2:] != smtplib.CRLF: q = q + smtplib.CRLF
q = q + "." + smtplib.CRLF
self.send(q)
else:
# Data to send is contained in a file.
fo = open(msg)
while (1):
buf = fo.read(16384)
if (buf == ""): break
qBuf = smtplib.quotedata(buf)
self.send(buf)
fo.close()
self.send(smtplib.CRLF + "." + smtplib.CRLF)
(code, msg) = self.getreply()
if (self.debuglevel > 0): print "data:", (code, msg)
return (code, msg)
评论列表
文章目录