Azzeddine
Azzeddine

Reputation: 196

Bash Command to send Email

I have a file which contains a list of email addresses. I would like to send out emails to this list via a bash command. If possible, have the command check for duplicates and not send the email to a duplicate email.

Sample File Input:

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

So in this example [email protected] should not receive a duplicate email. Does anyone have any Bash commands to point me in the right direction?

Upvotes: 0

Views: 456

Answers (2)

Explosion Pills
Explosion Pills

Reputation: 191729

mail -s "Subject" $(sort -u recipients-file) <<<"msg"

Upvotes: 0

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 184955

Try doing this with your file :

mail -s subject "$(sed '/^$/d;s/ *//g' file.txt | sort -u | paste -sd ",")" <<EOF
message here
EOF

Upvotes: 3

Related Questions