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:
4
main.py
4
main.py
@@ -11,9 +11,9 @@ while running is True:
|
|||||||
invoiceNumber = str(input())
|
invoiceNumber = str(input())
|
||||||
InvoiceDatabase.load_sheet(invoiceNumber)
|
InvoiceDatabase.load_sheet(invoiceNumber)
|
||||||
elif option == 2:
|
elif option == 2:
|
||||||
sendEmail.send_email(True,'ALL')
|
sendEmail.send_email(True, 'ALL')
|
||||||
elif option == 3:
|
elif option == 3:
|
||||||
sendEmail.send_email()
|
sendEmail.send_email(False, 'ALL')
|
||||||
elif option == 4:
|
elif option == 4:
|
||||||
running = False
|
running = False
|
||||||
else:
|
else:
|
||||||
|
|||||||
23
sendEmail.py
23
sendEmail.py
@@ -9,14 +9,15 @@ import InvoiceDatabase
|
|||||||
def send_email(test, record):
|
def send_email(test, record):
|
||||||
|
|
||||||
port = 25
|
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()
|
orders = InvoiceDatabase.just_work()
|
||||||
for each in orders:
|
for each in orders:
|
||||||
info = InvoiceDatabase.record_lookup(each)
|
info = InvoiceDatabase.record_lookup(each)
|
||||||
|
|
||||||
OrderNumber = info[0]
|
OrderNumber = info[0]
|
||||||
OrderDate = info[1]
|
OrderDate = datetime.strptime(info[1], '%Y-%m-%d %I:%M:%S')
|
||||||
UserLogon = info[2]
|
UserLogon = info[2]
|
||||||
Name = info[3] + ' ' + info[4]
|
Name = info[3] + ' ' + info[4]
|
||||||
ChargeCode = info[5]
|
ChargeCode = info[5]
|
||||||
@@ -36,7 +37,6 @@ def send_email(test, record):
|
|||||||
ShippingState = info[14]
|
ShippingState = info[14]
|
||||||
ShippingPostalCode = info[15]
|
ShippingPostalCode = info[15]
|
||||||
|
|
||||||
|
|
||||||
# if ShippingCompany != 'None' and ShippingAddress2 == 'None':
|
# if ShippingCompany != 'None' and ShippingAddress2 == 'None':
|
||||||
block = '''
|
block = '''
|
||||||
<br>{name}
|
<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
|
BORDER-LEFT: #838282 1px solid; MARGIN-TOP: 10px"" borderColor=#838282 cellSpacing=0 cellPadding=5
|
||||||
rules=all border=1><TBODY>
|
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>
|
<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)
|
items = InvoiceDatabase.all_items(OrderNumber)
|
||||||
@@ -135,7 +135,7 @@ def send_email(test, record):
|
|||||||
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300">
|
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300">
|
||||||
<P>
|
<P>
|
||||||
<B>Order Number:</B> {OrderNumber}
|
<B>Order Number:</B> {OrderNumber}
|
||||||
<BR><B>Order Date:</B> {OrderDate}
|
<BR><B>Order Date:</B> {OrderDate:%m-%d-%Y %I:%M:%S}
|
||||||
<BR><B>User Logon:</B> {UserLogon}
|
<BR><B>User Logon:</B> {UserLogon}
|
||||||
<BR><B>Name:</B> {Name}
|
<BR><B>Name:</B> {Name}
|
||||||
<BR><B>Charge Code:</B> {ChargeCode}
|
<BR><B>Charge Code:</B> {ChargeCode}
|
||||||
@@ -176,18 +176,19 @@ def send_email(test, record):
|
|||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
msg['Subject'] = 'INVOICE ' + InvoiceNumber
|
msg['Subject'] = 'INVOICE ' + InvoiceNumber
|
||||||
if test is True:
|
if test is True:
|
||||||
msg['To'] = 'ddembinski@gll.com'
|
msg['To'] = 'dan.dembinski@gmail.com'
|
||||||
msg['Cc'] = 'ddembinski@gll.com'
|
|
||||||
msg['Bcc'] = 'ddembinski@gll.com'
|
|
||||||
else:
|
else:
|
||||||
msg['To'] = InvoiceEmailAddress
|
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.add_header('Content-Type', 'text/html')
|
||||||
msg.attach(bodyHTML)
|
msg.attach(bodyHTML)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with smtplib.SMTP(smtp_server, port, timeout=120) as server:
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user