The following program takes advantage of the SMTP protocol to send a solid message. The next optimizations make it possible to collect messages using POP3 or IMAP protocols.
#/usr/bin/env python#-*-Coding:utf8-*-ImportSmtplib fromEmail.mime.textImportMimetextclassMail_helper:def __init__(self): Self.username= Raw_input ('Username:') Self.password= Raw_input ('Password:') defSend (self): host='smtp.163.com'Port= 25receiver= Raw_input ('Send to:') Title= Raw_input ('Title:') Body='<p>'+raw_input ('content:')+'</p>'msg= Mimetext (Body,'HTML') msg['subject'] =title msg[' from'] =self.username msg[' to'] =receiver S=Smtplib. SMTP (host, Port) S.login (Self.username, Self.password) s.sendmail (self.username, receiver, msg.as_string ()) Print 'Mail has been sent.'if __name__=='__main__': Mailer=Mail_helper () mailer.send ( )
Python implementation Send mail