'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.'

def data(self, msg):

    self.putcmd('data')
    (code, repl) = self.getreply()
    if (self.debuglevel > 0):
        print >>stderr, 'data:', (code, repl)
    if (code != 354):
        raise SMTPDataError(code, repl)
    else:
        q = quotedata(msg)
        if (q[(-2):] != CRLF):
            q = (q + CRLF)
        q = ((q + '.') + CRLF)
        self.send(q)
        (code, msg) = self.getreply()
        if (self.debuglevel > 0):
            print >>stderr, 'data:', (code, msg)
        return (code, msg)
