from time import time
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
def sendmail():
smtpserver = ""
user = ""
password = ""
sender = ""
receive = ""
subject = "dasfowefe"
content = "<html><h1 style='color:red'>zabbixdjflajdflkajfklasjdfklasjdlf</h1></html>"
msgRoot = MIMEMultipart()
send_file = open(r"/root/{}".format("aa.sh"), "rb").read()
att = MIMEApplication(send_file, )
att['Content-Type'] = 'application/octet-stream'
att.add_header('Content-Disposition', 'attachment', filename='{}'.format("aa.sh"))
msgRoot.attach(MIMEText(content, 'html', 'utf-8'))
msgRoot['Subject'] = subject
msgRoot['From'] = sender
msgRoot['To'] = ''.join(receive)
msgRoot.attach(att)
smtp = smtplib.SMTP_SSL(smtpserver, 465)
smtp.helo(smtpserver)
smtp.ehlo(smtpserver)
smtp.login(user, password)
print("Send email start...")
smtp.sendmail(sender, receive, msgRoot.as_string())
smtp.quit()
print("email send end!")
sendmail()