Scripted Email

Used to send email to list of people from flat file. Usually when sending from server you want the reply-to set correctly so the replies go to a proper email account.

Input File

The input file is cre.txt and has the following format

  • Header: Username Password Email
  • Rows: userid password email
  • Fields are space delimited

Sample file

Username Password Email
hjames N8dseRzx8l
itom 08sdfssRPd
klucy 1eh4g6y88

Updates to script

Things to update in script are

  • input file location (input)
  • Subject (subject1)
  • Body as appropriate
  • replyto field


The tr command is optional. In case the file arrived from DOS/WINDOWS it may have funny characters

cat cre.txt | tr -d '\015' > cre1.txt
subject1="Some Subject"
while read -r line
    IFS=" " read -r f1 f2 f3 <<<"$line"
    if [ ! $f1 = "Username" ]; then
        echo "Emailing $f3 ..."
        body1="You Userid is $f1 and Password is $f2"
        echo $body1 | mailx -s "$subject1" -S "$f3"
done <"$input"


for loop mass

QR Code
QR Code tech:linux:scripted_email (generated for current page)