I'm trying to add a field to the body of an email sent out to customers, so that the name of the customer appears within the body. The string in the field will vary depending on the order. Instead of the email starting with 'Dear Customer,' would start with 'Dear Jane Bennett,' for salesnumber 1 would start with 'Dear John Wickham,' for salesnumber 2, etc. Adding a snippet of the relevant code below. from My_Modules.core_modules import SendEmail, SetEnvironment, GetSQLConnection, ExecuteSQLFile, ComposeEmail import sys import os import re class main: def GetOrders(): Sales = list() fields = ['ponum', 'salesnumber', 'Name', 'CustEmail'] with GetSQLConnection(env['server'], env['database'], Logger) as conn: cursor = conn.cursor() R, C, I = ExecuteSQLFile(env['Dirs']['Queries'], 'Shipped.sql', (), cursor, Logger) if len(R) == 0: Logger.debug('No new orders.') sys.exit() for r in R: record = tuple([r[I.index(x)] for x in fields]) Sales.append(record) return Sales, fields def WriteEmailBody(o, f): body = """<p><i>Dear Customer,</i></p> <p><i>This message serves to notify you that your order has shipped. Please keep an eye on your email PO <b>%s</b> for shipping updates.</i></p> """ % o[f.index('ponum')] body += "<p><i>CS</i></p>" return body Continue reading...