テスト学習の自動化--Pythonメール添付ファイル付きメール送信

1461 ワード

#         
#   :  C:\Users\lj\Desktop\    baidu.png          
import smtplib                           #      
from email.mime.text import MIMEText    #      
from email.mime.multipart import MIMEMultipart  #      

#       
smtpserver='smtp.163.com'

#         (       )
user='[email protected]'
password='******'

#       
sender='[email protected]'
receives=['[email protected]','[email protected]']


#         
subject='Web Selenium       '
content='

!

' # send_file=open(r"C:\Users\lj\Desktop\\baidu.png",'rb').read() att=MIMEText(send_file,'base64','utf-8') # att["Content-Type"]='application/octet-stream' # att["Content-Disposition"]='attachment;filename="logo.png"' # msgRoot=MIMEMultipart() msgRoot.attach(MIMEText(content, 'html', 'utf-8')) msgRoot['subject']=subject msgRoot['From']=sender msgRoot['To'] = ','.join(receives) msgRoot.attach(att) #SSL 465 smtp = smtplib.SMTP_SSL(smtpserver, 465) #HELO smtp.helo(smtpserver) # smtp.ehlo(smtpserver) # smtp.login(user,password) print("Start send email...") smtp.sendmail(sender,receives,msgRoot.as_string()) smtp.quit() print("Send End!")