root/software/misc/email_test.py @ 058717b0
| 26cc955b | David Sorber | #!/usr/bin/python3
|
|
import datetime
|
|||
from email.mime.text import MIMEText
|
|||
from smtplib import SMTP_SSL
|
|||
import socket
|
|||
import subprocess
|
|||
import sys
|
|||
RELAY_EMAIL = 'dsorber.phalanx@gmail.com'
|
|||
RELAY_PASSWD = "You'reNotMySupervisor"
|
|||
TO_EMAIL = 'baranovich@gmail.com'
|
|||
SEP = '-' * 80
|
|||
# 20210122 - Note to self if you're having STMP authentication issues check:
|
|||
# https://stackabuse.com/how-to-send-emails-with-gmail-using-python/
|
|||
#
|
|||
def send_email(subject, msg_text):
|
|||
msg = MIMEText(msg_text, 'plain')
|
|||
msg['Subject'] = subject
|
|||
msg['To'] = TO_EMAIL
|
|||
try:
|
|||
conn = SMTP_SSL('smtp.gmail.com')
|
|||
conn.set_debuglevel(True)
|
|||
conn.login(RELAY_EMAIL, RELAY_PASSWD)
|
|||
try:
|
|||
conn.sendmail(RELAY_EMAIL, TO_EMAIL, msg.as_string())
|
|||
finally:
|
|||
conn.close()
|
|||
except Exception as exc:
|
|||
print('ERROR')
|
|||
print(exec)
|
|||
sys.exit("Mail failed: {}".format(exc))
|
|||
def main():
|
|||
print('Email Test Util\n')
|
|||
send_email('EMAIL TEST', str(datetime.datetime.now()))
|
|||
if __name__ == '__main__':
|
|||
sys.exit(main())
|