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:
23
sendEmail.py
23
sendEmail.py
@@ -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}
|
||||
<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>Name:</B> {Name}
|
||||
<BR><B>Charge Code:</B> {ChargeCode}
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user