substitute values in email via python
I am NEW to python and trying to write a script that will send an email (In HTML) to a group of people.
This python script will execute a perl script that will read an excel file and save it in a .txt file, once the file is created the python script will open the txtFile and create an array of all the names:
Here is the snip from the scripts
file = open(txtFile, "r" )
array = []
for line in file:
array.append( line )
print array[2]
print array[1]
$ ./tempSendOnCall.py
Branch number is 2011.06
07-15-11
Ash dy
Joe Des
Once this part is over I am creating an email (In the same script) that will send it out and I need to replace the names of the oncall and lead on call persons with the results from the Array as this changes every week.
Here is the email portion:
sendmail="/p4/sendEmail"
SERVER = "ServerName"
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
me = "name@domain"
you = "name@domain"
msg = MIMEMultipart('alternative')
msg['Subject'] = "3LS / QA / SA on-call review"
msg['From'] = me
msg['To'] = you
text = "test"
html = """\
<html>
Message
Hi Ash dy, (Need to be updated from Array[1])
starting on DATE (Should ready from date = time.strftime("%m-%d-%y"))
Joe Des (Should be replaced with Array[2]) is the 3LS lead for this week.\n
Let me know if you have any questions,
"""
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
s = smtplib.SMTP(SERVER)
s.sendmail(me, you, msg.as_string())
s.quit()
I have everything working for me, but I can’t find a way to replace the Array values, or date, within that email!!
Please help 🙂
-guy
Allow me to direct your attention to the format string function
Of course, it will need access to your Array variable to work.