Skip to content

Commit

Permalink
Create notification.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 10, 2024
1 parent 76f0c20 commit 4bdcb86
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import smtplib
from email.mime.text import MIMEText

class NotificationSender:
def __init__(self, email_config):
self.email_config = email_config

def send_notification(self, message):
msg = MIMEText(message)
msg['Subject'] = 'System Monitoring Alert'
msg['From'] = self.email_config['from']
msg['To'] = self.email_config['to']

server = smtplib.SMTP(self.email_config['smtp_server'])
server.starttls()
server.login(self.email_config['username'], self.email_config['password'])
server.sendmail(self.email_config['from'], self.email_config['to'], msg.as_string())
server.quit()

if __name__ == '__main__':
email_config = {
'from': '[email protected]',
'to': '[email protected]',
'smtp_server': 'smtp.example.com',
'username': 'monitor',
'password': 'password'
}
notification_sender = NotificationSender(email_config)
notification_sender.send_notification('Test notification')

0 comments on commit 4bdcb86

Please sign in to comment.