|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import csv |
| 4 | +import time |
| 5 | +from email.mime.text import MIMEText |
| 6 | +import ssl |
| 7 | +import smtplib |
| 8 | + |
| 9 | +from email_credentials import EMAIL, PASSWORD, PORT, SMTP_SERVER |
| 10 | +# PORT for local server is 25, for Gmail is 465 |
| 11 | +# SMTP server may be something like 'smtp.gmail.com' |
| 12 | + |
| 13 | + |
| 14 | +def get_credentials_filename(): |
| 15 | + credentials_filename = 'show_credentials.csv' |
| 16 | + if len(sys.argv) > 1: |
| 17 | + credentials_filename = sys.argv[1] |
| 18 | + assert(os.path.exists(credentials_filename)) |
| 19 | + return credentials_filename |
| 20 | + |
| 21 | +def main(): |
| 22 | + credentials_filename = get_credentials_filename() |
| 23 | + |
| 24 | + context = ssl.create_default_context() |
| 25 | + |
| 26 | + with smtplib.SMTP_SSL(SMTP_SERVER, PORT, context=context) as server: |
| 27 | + server.login(EMAIL, PASSWORD) |
| 28 | + |
| 29 | + with open(credentials_filename, newline='') as infile: |
| 30 | + reader = csv.reader(infile) |
| 31 | + for row in reader: |
| 32 | + name, start_date, start_time, end_date, end_time, login, password, emails = row |
| 33 | + if start_date == 'startDate': |
| 34 | + continue |
| 35 | + |
| 36 | + recipient_list = emails.split(':') |
| 37 | + |
| 38 | + msg = MIMEText(f'''Welcome to a new and exciting term for KRLX!\nWe are very excited to hear you live on air for {name}.\nBelow, you will find your login credentials for streaming.\n\nlogin: {login}\npassword: {password}\n\n<3 KRLX IT''') |
| 39 | + msg['Subject'] = f'KRLX Credentials for {name}' |
| 40 | + msg['From'] = EMAIL |
| 41 | + msg['To'] = ', '.join(recipient_list) |
| 42 | + |
| 43 | + server.sendmail(EMAIL, recipient_list, msg.as_string()) |
| 44 | + |
| 45 | +if __name__ == '__main__': |
| 46 | + main() |
0 commit comments