Reputation: 101
I'm looking to loop through an index and create a string to be placed into the body of an email. There will be a comparison between values in two lists to determine whether they are to be added to the string.
I need the string to be displayed over several lines (one for each iteration which meets the criteria) but it's currently applying it as a single line of text in the actual email.
This is the email def:
def Emailer(message, subject, recipient):
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = recipient
mail.Subject = subject
mail.GetInspector
index = mail.HTMLbody.find('>', mail.HTMLbody.find('<body'))
mail.HTMLbody = mail.HTMLbody[:index + 1] + message + mail.HTMLbody[index + 1:]
mail.Display()
This part is what is used to create the string:
body = ""
for i, buyer in enumerate(buyers):
priceO = pricesOLD[i]
priceN = pricesNEW[i]
if priceN > priceO:
body = body + buyer + "\n"
if len(body) > 0:
Emailer(body,'subject','[email protected]')
else:
print("No Matches")
Upvotes: 6
Views: 4905