Commented out sendmail parts for testing. Added SentInvoice table that tracks when invoices were sent. Added InvoiceID and InvoiceSent columns to Invoice table. Now tracks which invoices haven't been sent and only sends those. Once hte invoice has been sent it marks it has having been sent in the database and adds the date to the SentInvoice table. Started adding parts to allow xlsx filent not to be hardcoded. Updated TableSetup using the PyCharm autogeneric SQL thing.
This commit is contained in:
20
sendEmail.py
20
sendEmail.py
@@ -13,10 +13,13 @@ def send_email(test, record):
|
||||
# smtp_server = 'mail.keystonerelay.com'
|
||||
smtp_server = 'printingconcepts-com.mail.protection.outlook.com'
|
||||
|
||||
sent_orders = []
|
||||
|
||||
orders = InvoiceDatabase.just_work()
|
||||
for each in orders:
|
||||
info = InvoiceDatabase.record_lookup(each)
|
||||
|
||||
InvoiceID = info[18]
|
||||
OrderNumber = info[0]
|
||||
OrderDate = datetime.strptime(info[1], '%Y-%m-%d %I:%M:%S')
|
||||
UserLogon = info[2]
|
||||
@@ -28,6 +31,7 @@ def send_email(test, record):
|
||||
BalanceDue = info[17]
|
||||
InvoiceDate = datetime.today().strftime('%m/%d/%Y')
|
||||
|
||||
|
||||
#shipping information
|
||||
ShippingCompany = info[8]
|
||||
ShippingFirstName = info[9]
|
||||
@@ -187,10 +191,14 @@ def send_email(test, record):
|
||||
|
||||
msg.add_header('Content-Type', 'text/html')
|
||||
msg.attach(bodyHTML)
|
||||
try:
|
||||
with smtplib.SMTP(smtp_server, port, timeout=120) as server:
|
||||
# server.sendmail(msg['From'], msg['To'] + ',' + msg['Cc'] + ',' + msg['Bcc'], msg.as_string())
|
||||
server.send_message(msg)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
# try:
|
||||
# with smtplib.SMTP(smtp_server, port, timeout=120) as server:
|
||||
# # server.sendmail(msg['From'], msg['To'] + ',' + msg['Cc'] + ',' + msg['Bcc'], msg.as_string())
|
||||
# server.send_message(msg)
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
if test is True:
|
||||
InvoiceDatabase.mark_sent(InvoiceID, InvoiceDate)
|
||||
sent_orders.append(OrderNumber)
|
||||
print(sent_orders)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user