#!/usr/bin/python3
# coding: utf-8

# email smtp server credentials

SMPT = '--your-smtp-server-url--'
SRC  = '--your-smtp-user-name--'
PWD  = '--your-smtp-password--'
PORT = 465 # usual 

# setup a default message
TGT = '--your-email-address--'
OBJ = 'Alert'
MSG = 'Raspberry Pi rebooted'

# Import smtplib for the actual sending function
import smtplib, ssl

# Import the email modules we'll need
from email.mime.text import MIMEText

# Allow for command line options to set the subject, target email and message
import argparse

parser = argparse.ArgumentParser(description='Send short email.')
parser.add_argument('-s', '--subject')
parser.add_argument('-t', '--to')
parser.add_argument('-m', '--msg') 

args = parser.parse_args()

if args.subject: OBJ = args.subject
if args.to:      TGT = args.to
if args.msg:     MSG = args.msg

# debug arguments  
#print(args)
#print('OBJ', OBJ)
#print('TGT', TGT)
#print('MSG', MSG)
#exit

# Create the message
msg = MIMEText(MSG)
msg['Subject'] = OBJ
msg['From'] = SRC
msg['To'] = TGT

# Send it 
context = ssl.create_default_context()
with smtplib.SMTP_SSL(SMPT, PORT, context=context) as server:
    server.login(SRC, PWD)
    server.sendmail(SRC, TGT, msg.as_string())

# ref: https://realpython.com/python-send-email/
