def sendEmail(toAddrs, subject, body): """ 发送邮件 """ transport = TSocket.TSocket(HOST, PORT) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = SendEmail.Client(protocol) transport.open() b = client.send(toAddrs, subject, body) transport.close()
def main(): # Make socket transport = TSocket.TSocket('localhost', 9090) # Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a client to use the protocol encoder client = SendEmail.Client(protocol) # Connect! print 'connecting ...' transport.open() b = client.send("*****@*****.**", u'主题', u'内容') transport.close()