Vikas Nale 663b6410d2 - Handle multiple database backups from different servers
- use json config file to store configurations
2025-07-05 15:28:35 +05:30

29 lines
840 B
Python

import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(EMAIL_HOST,EMAIL_PORT, EMAIL_USER,EMAIL_PASS, subject, body, to_emails, html=False):
if isinstance(to_emails, str):
to_emails = [to_emails]
msg = MIMEMultipart()
msg["From"] = EMAIL_USER
msg["To"] = ", ".join(to_emails)
msg["Subject"] = subject
if html:
msg.attach(MIMEText(body, "html"))
else:
msg.attach(MIMEText(body, "plain"))
try:
with smtplib.SMTP(EMAIL_HOST, EMAIL_PORT) as server:
server.starttls()
server.login(EMAIL_USER, EMAIL_PASS)
server.sendmail(EMAIL_USER, to_emails, msg.as_string())
return True
except Exception as e:
print(f"Error sending email: {e}")
return False