updated the main menu loop so that it's possible to send live emails. Converting the OrderDate variable to a time object it can be formatted in the email body. Switched to send_message to handle Cc and Bcc better. Now sending from Matt's email. Test email set to external address. Matt cannot use mail relay for external mail, waiting for Keystone to advise.

This commit is contained in:
Dan Dembinski
2021-03-23 15:23:52 -04:00
parent 56722752ac
commit bf2d1b3f99
2 changed files with 14 additions and 13 deletions

View File

@@ -11,9 +11,9 @@ while running is True:
invoiceNumber = str(input())
InvoiceDatabase.load_sheet(invoiceNumber)
elif option == 2:
sendEmail.send_email(True,'ALL')
sendEmail.send_email(True, 'ALL')
elif option == 3:
sendEmail.send_email()
sendEmail.send_email(False, 'ALL')
elif option == 4:
running = False
else:

View File

@@ -9,14 +9,15 @@ import InvoiceDatabase
def send_email(test, record):
port = 25
smtp_server = "gll-com.mail.protection.outlook.com"
smtp_server = 'gll-com.mail.protection.outlook.com'
# smtp_server = 'mail.keystonerelay.com'
orders = InvoiceDatabase.just_work()
for each in orders:
info = InvoiceDatabase.record_lookup(each)
OrderNumber = info[0]
OrderDate = info[1]
OrderDate = datetime.strptime(info[1], '%Y-%m-%d %I:%M:%S')
UserLogon = info[2]
Name = info[3] + ' ' + info[4]
ChargeCode = info[5]
@@ -36,7 +37,6 @@ def send_email(test, record):
ShippingState = info[14]
ShippingPostalCode = info[15]
# if ShippingCompany != 'None' and ShippingAddress2 == 'None':
block = '''
<br>{name}
@@ -56,7 +56,7 @@ def send_email(test, record):
BORDER-LEFT: #838282 1px solid; MARGIN-TOP: 10px"" borderColor=#838282 cellSpacing=0 cellPadding=5
rules=all border=1><TBODY>
<TR><TD style=""FONT-WEIGHT: 800""><B>Quantity</B></TD><TD style=""FONT-WEIGHT: 800""><B>Document ID</B></TD>
<TD style=""FONT-WEIGHT: 800""><B>Product Name</B</TD><TD style=""FONT-WEIGHT: 800""><B>Sales</B></TD></TR>
<TD style=""FONT-WEIGHT: 800""><B>Product Name</B></TD><TD style=""FONT-WEIGHT: 800""><B>Sales</B></TD></TR>
'''
items = InvoiceDatabase.all_items(OrderNumber)
@@ -135,7 +135,7 @@ def send_email(test, record):
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300">
<P>
<B>Order Number:</B> {OrderNumber}&nbsp;
<BR><B>Order Date:</B> {OrderDate}&nbsp;
<BR><B>Order Date:</B> {OrderDate:%m-%d-%Y %I:%M:%S}&nbsp;
<BR><B>User Logon:</B> {UserLogon}&nbsp;
<BR><B>Name:</B> {Name}&nbsp;
<BR><B>Charge Code:</B> {ChargeCode}&nbsp;
@@ -176,18 +176,19 @@ def send_email(test, record):
msg = MIMEMultipart()
msg['Subject'] = 'INVOICE ' + InvoiceNumber
if test is True:
msg['To'] = 'ddembinski@gll.com'
msg['Cc'] = 'ddembinski@gll.com'
msg['Bcc'] = 'ddembinski@gll.com'
msg['To'] = 'dan.dembinski@gmail.com'
else:
msg['To'] = InvoiceEmailAddress
msg['From'] = 'ddembinski@gll.com'
msg['Cc'] = 'Carrie Higgins <chiggins@gll.com>'
msg['Bcc'] = 'ddembinski@gll.com'
msg['From'] = 'Matt MulQueeny <mmulqueeny@printingconcepts.com>'
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.as_string())
# server.sendmail(msg['From'], msg['To'] + ',' + msg['Cc'] + ',' + msg['Bcc'], msg.as_string())
server.send_message(msg)
except Exception as e:
print(e)