#-*-Coding: UTF-8 -*- #===================================================== === # Import smtplib and MIMEText #===================================================== === From email. mime. text import MIMEText Import smtplib #===================================================== === # To whom, send it to two people here #===================================================== === Mailto_list = ["naughty610@qq.com", "1034791200@qq.com"] #===================================================== === # Set the server, user name, password, and mailbox suffix #===================================================== === Mail_host = "smtp.qq.com" Mail_user = "naughty610" Mail_pass = "here is your password" Mail_postfix = "qq.com" #===================================================== === # Send an email #===================================================== === Def send_mail (to_list, sub, content ): ''''' To_list: to whom Sub: topic Content: content Send_mail ("aaa@126.com", "sub", "content ") ''' Me = mail_user + "<" + mail_user + "@" + mail_postfix + ">" Msg = MIMEText (content) Msg ['subobject'] = 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 t Exception, e: Print str (e) Return False If _ name _ = '_ main __': If send_mail (mailto_list, "here is subject", "here is content "): Print "sent successfully" Else: Print "failed to send" |