#-*-Coding:utf-8-*-
From Email.mime.text import Mimetext
From Email.header Import Header
Import Smtplib
def send_mail (file_new):
f = open (File_new, ' RB ')
Mail_body = F.read ()
F.close ()
msg = Mimetext (mail_body, ' html ', ' Utf-8 ')
msg[' Subject ' = Header ("Automated test Report", ' Utf-8 ')
SMTP = Smtplib. SMTP ()
Smtp.connect ("smtp.126.com")
Smtp.login ("[Email protected]", ' Password ')
Smtp.sendmail ("[Email protected]", "[email protected]", msg.as_string ())
Smtp.quit ()
Print "Email has send out!"
Send_mail ("D:\\123456.txt")
Note: The above code can be sent automatically mail, but in the sending of Chinese or English mixed files, there will be garbled situation. For the topic, the reply person involves the Chinese character, must use the header ("xxxx", "Utf-8") the way to encode the conversion. As for the content, don't convert it into utf-8.
Automatically send mail using Python