Shell script to get notification from the server

Installing Requirements

https://pypi.org/project/py-simple-email/

pip install py-simple-email

Creating the shell in python

sudo nano /usr/local/bin/notify
#!/usr/bin/python3
from py_simple_email import Email
from datetime import datetime 
datetime_now = datetime.now()

email = Email( 
    EMAIL_HOST = 'email-smtp.ap-south-1.amazonaws.com', 
    EMAIL_HOST_USER = 'XXXXXXXXXXXXXXXXXXXXXX', 
    EMAIL_HOST_PASSWORD = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 
    EMAIL_PORT= 587,
    EMAIL_USE_TLS = True,
    DEFAULT_FROM_EMAIL = 'Sanjay Sikdar <hello@sanjaysikdar.dev>',
)

server_name = 'dev server'
domain = 'https://prod.sanjaysikdar.dev/'
ip = '128.128.128.128'


message = """\
Action Date & Time: {time}
Domain: {domain} ({ip})

""".format(time=datetime_now, domain=domain, ip=ip)

emails = ['hello@sanjaysikdar.dev', 'test@example.com']
for email_address in emails:
    email.send(
        to_email=email_address,
        subject=f'{server_name} performed some action',
        msg=message,
    )
sudo chmod +x /usr/local/bin/notify

Now you can type notify anywhere in your terminal - server notifications will send to the selected emails.