Wednesday, June 16, 2021

Sending mail using Unix and Linux commands

Unix Commands for Sending email
-------------------------------------------------

sending file as attachment

1) uuencode filename.txt | mailx -s "filename details"  -c abc@test.com -r noreply@test.com sender@test.com

sending file as attachment

2) mail -s "Test mail" abc@test.com < TestFile.txt


3)  (echo "Hi All, \n Please find the attached details in the email \n Thanks \n Application Team"; uuencode File.txt attahedFile.txt) | mailx -s "File details" -c abc@test.com -r noreply@test.com sender@test.com

Linux Commands for Sending email
--------------------------------------------------

1. Below command will send mail sending hello text mail in body

echo "Hello" | mailx -s "Test Email " -r abc@test.com to@test.com

-r means sender who is sending the mail

2. Below command will send text file in the body

mailx -s "Test mail subject" -r abc@test.com to@test.com < sample.txt

3. Below command will also send mail similar to above

cat sample.txt | mailx -s "Test mail subject" -c cc@test.com -r from@test.com to@test.com 

-c means cc to list.

4. Below command will send attachment in email. We use -a for attachment

echo "Hello, Please find the attached Report" | mailx -s "Report Details" -a report.html -r from@test.com to@test.com

5. Below command will variable as attachment

echo "$variable"  | mail -s "Testing" -r from@test.com to@test.com

6. Below command will sent mail with attachment with body text include new lines.

echo -e "Hi Team, \n Please find the attached Report" | mailx -s "Test Report Subject"  -a "attachmentpath+filename" -r noreply@test.com to@test.com


No comments: