dgowen
dgowen

Reputation: 11

How do I send an email using awk to a list of email addresses in a text file?

If I have a text file with a list of email addresses, how can I go through the list and send an email to each of those email addresses with a text file as the message. I.e. I want to take in an email as a variable so I can execute this command:

mail -s "Welcome" [email protected] < welcome.txt

Upvotes: 1

Views: 2043

Answers (2)

rush
rush

Reputation: 2564

for example you have a mails_addresses.txt file with one address per line like that:

[email protected]
[email protected]
[email protected]

In case you have another complex structure which you need to parse with for example awk you should to show it us.

So you need just to write a loop which will read it and send it to mail command:

while read MAIL
do
    mail -s "Welcome" "$MAIL" < welcome.txt
done < mails_addresses.txt

Upvotes: 6

Igor Chubin
Igor Chubin

Reputation: 64603

You can do this even without awk:

cat users-list | while read addr
do
mail -s "Welcome" "$addr" < welcome.txt
done

Upvotes: 1

Related Questions