ImportSmtplibImportUrllib fromEmail.mime.textImportmimetextmailto_list= ["[email protected]"]mail_host="smtp.139.com" #setting up the serverMail_user ="[email protected]" #User nameMail_pass ="[email protected]" #PasswordMail_postfix ="139.com" #outgoing outbox suffixdefSend_mail (to_list, title, content):#to_list: Recipient; sub: subject; Content: Message contentsme = Mail_user.split ("@") [0]+"<"+ Mail_user +">" #Here the hello can be arbitrarily set, after receiving the letter, will be displayed according to the settingsmsg = mimetext (content, _subtype='HTML', _charset='Utf-8')#Create an instance, which is set to HTML-formatted mailmsg['Subject'] = Title#Set Thememsg[' from'] =Me msg[' to'] =";". Join (to_list)Try: S=Smtplib. SMTP () s.connect (mail_host)#connecting to an SMTP serverS.login (Mail_user, Mail_pass)#Login ServerS.sendmail (Me, To_list, msg.as_string ())#Send mails.close ()returnTrueexceptException, E:PrintStr (e)returnFalsesend_mail (Mailto_list,"Message Subject","content")
Python Send mail