Skip to content

Instantly share code, notes, and snippets.

@jatinchauhann
Created August 30, 2019 10:04
Show Gist options
  • Save jatinchauhann/4b9e35952ac4231255e0dd2e2318e5f3 to your computer and use it in GitHub Desktop.
Save jatinchauhann/4b9e35952ac4231255e0dd2e2318e5f3 to your computer and use it in GitHub Desktop.
def send_mail(franchise_name, send_from, send_to, subject, email_content, files,
server_host, server_port):
msg = MIMEMultipart()
msg['From'] = send_from
msg['To'] = send_to
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.preamble = """
Please open these reports using Google Chrome!"""
msg.attach(MIMEText(email_content, 'html'))
f = "{0} HDFS Stats.html".format(franchise_name)
part = MIMEApplication(files, Name=os.path.basename(f))
part['Content-Disposition'] = 'attachment; filename="%s"' % os.path.basename(f)
msg.attach(part)
smtp = smtplib.SMTP(server_host, server_port)
smtp.starttls()
smtp.sendmail(send_from, send_to, msg.as_string())
smtp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment