Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6142697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:25:26+00:00 2026-05-23T18:25:26+00:00

substitute values in email via python I am NEW to python and trying to

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:25:27+00:00Added an answer on May 23, 2026 at 6:25 pm

    Allow me to direct your attention to the format string 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to substitute something in a string in python and am having some
I've been trying to code a Perl script to substitute some text on all
Is there a way that I can give python a list of values like
I am writing a script that deals with hex color values and I want
I am trying to display the actual values of the parameters that were supplied
I'm trying to change values in my application.properties file and I'm running into issues
I am new to PHP and I am trying to work on this one
I am trying to use PEAR Mail to send using an external smtp server.
Prototype's Template class allows you to easily substitute values into a string template. Instead
I am using c:forEach inside rich:dataTable. But c:forEach doesn't substitute the values for answer.choices

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.