-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendDuesReminder.py
More file actions
33 lines (29 loc) · 1.39 KB
/
sendDuesReminder.py
File metadata and controls
33 lines (29 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! python3
# sendDuesReminders.py - Sends emails based on payment status in spreadsheet.
import openpyxl, smtplib, sys
# Open the spreadsheet and get the latest dues status.
wb = openpyxl.load_workbook('C:\\Users\\user\\Desktop\\PYTHON\\duesRecords.xlsx')
sheet = wb['Sheet1']
lastCol = sheet.max_column
latestMonth = sheet.cell(row=1, column=lastCol).value
# TODO: Check each member's payment status.
unpaidMembers = {}
for r in range(2, sheet.max_row + 1):
payment = sheet.cell(row=r, column=lastCol).value
if payment != 'paid':
name = sheet.cell(row=r, column=1).value
email = sheet.cell(row=r, column=2).value
unpaidMembers[name] = email
# TODO: Log in to email account.
smtpObj = smtplib.SMTP_SSL('smtp.gmail.com', 465)
smtpObj.ehlo()
smtpObj.login('boluwatifelekeoduoye@gmail.com', sys.argv[1])
# TODO: Send out reminder emails.
# Send out reminder emails.
for name, email in unpaidMembers.items():
body = "Subject: %s dues unpaid.\nDear %s,\nRecords show that you have not paid dues for %s. Please make this payment as soon as possible. Thank you!'" % (latestMonth, name, latestMonth)
print('Sending email to %s...' % email)
sendmailStatus = smtpObj.sendmail('boluwatifelekeoduoye@gmail.com', email, body)
if sendmailStatus != {}:
print('There was a problem sending email to %s: %s' % (email, sendmailStatus))
smtpObj.quit()