substitute values in email via python
<p>substitute values in email via python</p>

<p>I am NEW to python and trying to write a script that will send an email (In HTML) to a group of people.</p>

<p>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:</p>

<p>Here is the snip from the scripts</p>

<pre><code>file = open(txtFile, "r" )
array = []
for line in file:
    array.append( line )

print array[2]
print array[1]
</code></pre>

<p>$ ./tempSendOnCall.py
Branch number is 2011.06
07-15-11
Ash dy
Joe Des</p>

<p>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.</p>

<p>Here is the email portion:</p>

<pre><code>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 = """\
&lt;html&gt;
  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()
</code></pre>

<p>I have everything working for me, but I can't find a way to replace the Array values, or date, within that email!!</p>

<p>Please help :-)</p>

<p>-guy</p>
