From 7030242ec312366b644cd997244b1337d23f5926 Mon Sep 17 00:00:00 2001 From: "Arun Johal (johala9)" Date: Wed, 31 Mar 2021 18:39:42 +0100 Subject: [PATCH] Update index.py --- RESIT/index.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/RESIT/index.py b/RESIT/index.py index 1ffcd5e..008589d 100644 --- a/RESIT/index.py +++ b/RESIT/index.py @@ -9,6 +9,14 @@ from email.message import EmailMessage #allows searching of directory (os is for Miscellaneous operating system interfaces) import os +def loginEmail(adminEmail, adminPass): + # Log into GMail server with admin/dev email (created bespoke for this proj) + server = smtplib.SMTP_SSL("smtp.gmail.com", 465) + server.login(adminEmail, adminPass) + + return server + + #email_sender function def email_sender(subsFile, articlesFile, announceFile, adminEmail, adminPass): # Pull out everything in excel file @@ -33,7 +41,7 @@ def email_sender(subsFile, articlesFile, announceFile, adminEmail, adminPass): else: # Repeat if other statments arent met continue - # Subject is set + # Subject is sets # TEMPLATE FILE TO BE USED DEPENDING ON SUBJECT/TYPE if emailTypeIn == 1: @@ -65,10 +73,8 @@ def email_sender(subsFile, articlesFile, announceFile, adminEmail, adminPass): # msg.add_header(subject,'text/html') msg['Subject'] = subject - - # Log into GMail server with admin/dev email (created bespoke for this proj) - server = smtplib.SMTP_SSL("smtp.gmail.com", 465) - server.login(adminEmail, adminPass) + + server = loginEmail(adminEmail, adminPass) # Allows correct indexing of arrays pulled from excel counter = 0 @@ -90,13 +96,13 @@ def email_sender(subsFile, articlesFile, announceFile, adminEmail, adminPass): #msg to admin to show that process is complete print("DONE") +# USER: CHANGE THESE VARIABLES BEFORE FUNCTION CALL # Change to whatever directory you are using subsFile = r"C:\Users\arunj\Documents\UniWork\Python\RESIT\subscribers.xlsx" articlesFile = r"C:\Users\arunj\Documents\UniWork\Python\RESIT\templates\ARTICLES" announceFile = r"C:\Users\arunj\Documents\UniWork\Python\RESIT\templates\ANNOUNCEMENTS" - # REPLACE WITH EMAIL/PASS -adminEmail = "@gmail.com" -adminPass = "" +adminEmail = "arunjohal.email.dev@gmail.com" +adminPass = "Password_21" email_sender(subsFile, articlesFile, announceFile, adminEmail, adminPass)