forked from shanto268/lab_manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_notifier.py
27 lines (23 loc) · 890 Bytes
/
email_notifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
class EmailNotifier:
def __init__(self, username, password):
self.username = username
self.password = password
def send_email(self, recipients, subject, message):
"""Send an email to the specified recipients."""
msg = MIMEMultipart()
msg['From'] = self.username
msg['To'] = ', '.join(recipients)
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(self.username, self.password)
text = msg.as_string()
server.sendmail(self.username, recipients, text)
server.quit()
except Exception as e:
print(f"Error sending email: {e}")