This article describes the Python implementation of the QQ mailbox to send mail methods. Share to everyone for your reference. The implementation method is as follows:
#-*-coding:utf-8-*-#========================================== # import Smtplib and Mimetext #============================ ============== from Email.mime.text import mimetext import smtplib #========================================== # who to send to, Send 2 people here #========================================== mailto_list=["naughty610@qq.com", "1034791200@qq.com"] #====== ==================================== # Set the server, user name, password, and the suffix of the mailbox #========================================== mail_host= " Smtp.qq.com "mail_user=" naughty610 "mail_pass=" Here's your password "mail_postfix=" qq.com "#======================== ================== # Send mail #========================================== def send_mail (to_list,sub,content): "' To_li ST: to whom Sub: content Send_mail ("aaa@126.com", "sub", "Contents") "me=mail_user+" < "+mail_user+" @ "+mail_pos tfix+ ">" msg = mimetext (content) msg[' Subject '] = Sub msg[' from '] = Me msg[' to '] = ";". Join (to_list) try:s = Smtplib. SMTP () s.connect (mail_host) S.login (MAil_user,mail_pass) S.sendmail (Me, To_list, msg.as_string ()) S.close () return True except Exception, E: Print str (e) return False if __name__ = = ' __main__ ': If Send_mail (Mailto_list, "Here are subject", "Here are Content"): Print "Send successfully" Else:print "Send Failed"
Hopefully this article will help you with Python programming.