Pages

Tuesday, April 12, 2016

mail command one liners

Home

For sending email to a single user
# echo "Test of Mail body" | mail -s "Mail subject" to@somedomain.com

Where,
echo command is used for specifying body of the email.
-s option is used for specifying the mail subject
to@somedomain.com is the ens user’s email ID

Re-write above command for multi recipients

# echo "Test of Mail body" | mail -s "Mail subject" recipient1@somedomain.com  recipient2@somedomain.com

For sending contents of a text file

# cat  somefile.txt  | mail -s "Mail subject" "user1@example.com,user2@example.com"

# mail -s "Mail subject" "user1@example.com,user2@example.com" < somefile.txt

For sending email with CC & Bcc

# echo "something" | mailx -s "subject" -b bcc_user@unixmantra.com -c cc_user@some.com  -r sender@some.com recipient@example.com

# mail -s "Mail subject" -c "cc_user@some.com" -b "bccuser@yahoo.com" "user@example.com" < somefile.txt

For sending email by attaching files:


# uuencode attachment-file attachment-file | mail -s "Mail subject" "to-user@example.com" < somefile.txt


No comments:

Post a Comment