There is a need to automatically send mail in the business, there is no function to add attachments.
At the same time, also solved the message in Chinese garbled situation.
Directly on the code:
Import Smtplib
From Email.mime.text import Mimetext
defMail_send (title, body): Host="smtp.163.com"Port= 465Sender="[email protected]"pwd="1234"receiver= ["[email protected]","[email protected]"] #set up message informationmsg = Mimetext (Body,'HTML','Utf-8')#Body UTF8msg["Accept-language"] ="ZH-CN"msg["Accept-charset"] ="Iso-8859-1,utf-8"msg['subject'] = TitleifIsinstance (title, Unicode)ElseUnicode (Title.decode ("UTF8"))#The title must be Unicode encodedmsg[' from'] =Sender msg[' to'] =",". Join (receiver) s=Smtplib. Smtp_ssl (host, port) S.login (sender, pwd) s.sendmail (sender, receiver, msg.as_string ())Print 'The mail named%s to%s is sended successly.'% (title, receiver)
Python smtp Send mail