-
Notifications
You must be signed in to change notification settings - Fork 0
/
reminder
49 lines (45 loc) · 2.06 KB
/
reminder
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
import pdfkit
import psycopg2
import os
import psutil
import json
import configparser
from datetime import date, datetime, timedelta
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
config = configparser.ConfigParser()
config.read('.config')
def sendEmail(invoiceNo, to, amount, duedate):
try:
html = "<html><head><title>Invoice</title></head><body style='font-family: Comic Sans MS'>Hi,<br><p>This is a reminder email generated by the system to follow up your unpaid invoice for the service, the due balance is $"+'{:,.2f}'.format(amount)+", please follow the instruction to pay before due date "+duedate+". If you have any questions, please contact me as soon as possible.<br><p>Kind regards, <br>Hurin Hu<br><a href=\"mailto:hurin@live.ca\">hurin@live.ca</a><br><a href=\"https://www.iceloof.com\">https://www.iceloof.com</a></p></body></html>"
filename = '/invoices/INV'+str(invoiceNo)+'.pdf'
msg = MIMEMultipart('mixed')
msg['Subject'] = "[Reminder] Invoice ("+str(invoiceNo)+")"
msg['From'] = "Iceloof Admin<"+config['email']['admin']+">"
msg['To'] = to
msg['Cc'] = config['email']['to']
part2 = MIMEText(html, 'html')
fp=open(filename,'rb')
att = MIMEApplication(fp.read(),_subtype="pdf")
fp.close()
att.add_header('Content-Disposition','attachment',filename='INV'+str(invoiceNo)+'.pdf')
msg.attach(att)
msg.attach(part2)
s = smtplib.SMTP_SSL(host=config['email']['host'],port=config['email']['port'])
s.ehlo()
s.login(config['email']['email'],config['email']['password'])
s.sendmail(msg['From'], [to, msg['Cc']], msg.as_string())
s.quit()
except:
menu()
def menu():
email = input('Email to: ')
amount = input('Amount: ')
duedate = input('Due: ')
invoiceNo = input('Invoice: ')
sendEmail(invoiceNo, email, float(amount), duedate)
if __name__ == "__main__":
menu()