Initial commit. Loads XLSX file from accounting into sqlite database. Sends HTML email. Started adding variable parts to body pulled from database.
This commit is contained in:
125
sendEmail.py
Normal file
125
sendEmail.py
Normal file
@@ -0,0 +1,125 @@
|
||||
import smtplib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.base import MIMEBase
|
||||
from datetime import datetime
|
||||
import InvoiceDatabase
|
||||
|
||||
|
||||
def send_email(test, record):
|
||||
|
||||
port = 25
|
||||
smtp_server = "gll-com.mail.protection.outlook.com"
|
||||
|
||||
orders = InvoiceDatabase.just_work()
|
||||
for each in orders:
|
||||
info = InvoiceDatabase.record_lookup(each)
|
||||
print(info)
|
||||
OrderNumber = info[0]
|
||||
OrderDate = info[1]
|
||||
UserLogon = info[2]
|
||||
Name = info[3] + ' ' + info[4]
|
||||
ChargeCode = info[5]
|
||||
InvoiceNumber = info[6]
|
||||
InvoiceEmailAddress = info[7]
|
||||
InvoiceDate = datetime.today().strftime('%m/%d/%Y')
|
||||
|
||||
|
||||
body = '''
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
<HTML><HEAD><TITLE>CFF Order Invoice</TITLE>
|
||||
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
|
||||
<META name=GENERATOR content="MSHTML 11.00.9600.18525">
|
||||
<META name=Author content="">
|
||||
<META name=Keywords content="">
|
||||
<META name=Description content="">
|
||||
<STYLE type=text/css>
|
||||
p,
|
||||
span,
|
||||
a,
|
||||
table,
|
||||
td,
|
||||
input,
|
||||
textarea,
|
||||
select,
|
||||
option {{
|
||||
font-family: Verdana, Tahoma, Geneva, Arial, Helvetica, sans-serif;
|
||||
font-weight: normal;
|
||||
font-size: 13px;
|
||||
margin: 0;
|
||||
}}
|
||||
</STYLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
|
||||
<TABLE style="BORDER-COLLAPSE: collapse" width="600">
|
||||
|
||||
<TR>
|
||||
<TD style="BORDER-BOTTOM: #000000 1px solid" width="300"><IMG src="http://cff.gli.us.com/store/custom/images/GLIHeader.png"></TD>
|
||||
<TD style="BORDER-BOTTOM: #000000 1px solid" width="300" align="right"><P style="FONT-SIZE: 18px; FONT-WEIGHT: normal; MARGIN-TOP: 10px"><I>INVOICE</I></P></TD>
|
||||
</TR>
|
||||
|
||||
<TR vAlign="top">
|
||||
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300">
|
||||
<SPAN contentEditable=false style="" PFVar="AddressBlock">Address Block</SPAN></TD>
|
||||
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300"> <BR><P><B>Make Checks Payable To:</B> <BR>Great Lakes Integrated <BR>4246 Hudson Dr.<BR>Stow, Ohio 44224<BR> </P></TD>
|
||||
</TR>
|
||||
|
||||
<TR vAlign="top">
|
||||
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300">
|
||||
<P>
|
||||
<B>Order Number:</B> {OrderNumber}
|
||||
<BR><B>Order Date:</B> {OrderDate}
|
||||
<BR><B>User Logon:</B> {UserLogon}
|
||||
<BR><B>Name:</B> {Name}
|
||||
<BR><B>Charge Code:</B> {ChargeCode}
|
||||
</P>
|
||||
</TD>
|
||||
|
||||
<TD style="VERTICAL-ALIGN: top" vAlign="top" width="300">
|
||||
<P>
|
||||
<B>Invoice Number:</B> {InvoiceNumber}
|
||||
<BR><B>Invoice Date:</B> {InvoiceDate}
|
||||
<BR><B>Customer Number:</B> 1925
|
||||
<BR><B>Terms:</B>Due in 30 days
|
||||
</P>
|
||||
</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD width="600" colSpan="2"><P style="MARGIN-TOP: 20px"><B>The order consists of the following items:</B> </P>
|
||||
<SPAN contentEditable=false style="" PFVar="OrderDetail"></SPAN>
|
||||
</TD>
|
||||
</TR>
|
||||
</TBODY>
|
||||
</TABLE>
|
||||
</BODY>
|
||||
</HTML>
|
||||
'''
|
||||
HTMLpart = body.format(OrderNumber=OrderNumber, OrderDate=OrderDate, UserLogon=UserLogon, Name=Name,
|
||||
ChargeCode=ChargeCode, InvoiceDate=InvoiceDate, InvoiceNumber=InvoiceNumber)
|
||||
|
||||
bodyHTML = MIMEText(HTMLpart, "html")
|
||||
|
||||
f = open("sample.html", 'w')
|
||||
f.write(HTMLpart)
|
||||
f.close()
|
||||
|
||||
msg = MIMEMultipart()
|
||||
msg['Subject'] = 'INVOICE ' + InvoiceNumber
|
||||
if test is True:
|
||||
msg['To'] = 'ddembinski@gll.com'
|
||||
else:
|
||||
# msg['To'] = InvoiceEmailAddress
|
||||
msg['To'] = 'ddembinski@gll.com'
|
||||
msg['From'] = 'ddembinski@gll.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())
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
Reference in New Issue
Block a user