[英]substitute values in email via python
substitute values in email via python通过 python 替换 email 中的值
I am NEW to python and trying to write a script that will send an email (In HTML) to a group of people.我是 python 的新手,我正在尝试编写一个脚本,将 email(在 HTML 中)发送给一群人。
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: 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 $./tempSendOnCall.py 分支编号是 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.一旦这部分结束,我将创建一个 email(在同一个脚本中)将其发送出去,我需要用阵列的结果替换待命人员的姓名和待命人员的姓名,因为每周都会发生变化。
Here is the email portion:这是 email 部分:
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请允许我将您的注意力引向格式字符串 function
html = """\
<html>
Message
Hi {0:}, (Need to be updated from Array[1])
starting on {1:} (Should ready from date = time.strftime("%m-%d-%y"))
{2:} (Should be replaced with Array[2]) is the 3LS lead for this week.\n
Let me know if you have any questions,
""".format(Array[1], time.strftime("%m-%d-%y"), Array[2])
Of course, it will need access to your Array variable to work.当然,它需要访问您的 Array 变量才能工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.