vkk05
vkk05

Reputation: 3222

sendmail command to send an email with txt file attachment

I am trying to send email from Perl script using sendmail command.

Email contains a attachment (.txt file).

Here is the command I have tried:

>:/usr/people/vkk > echo "Subject:Report" | sendmail -t [email protected] < "/usr/people/vkk/Downloads/report_daily_2022_08_24_19_30_17.txt"
Ambiguous input redirect.

When I add echo "Subject:Report" option it gives following message -

Ambiguous input redirect

What is the right syntax to send an email with an attachment and subject line using sendmail command.

Upvotes: 0

Views: 3581

Answers (1)

Md. Imran Ali
Md. Imran Ali

Reputation: 21

It is not a good idea to send an attachment using sendmail command because you have to encoded the attachment by uuencode. So it is better to use mail or mutt command to sending attachment. Below command is the example for mail command.

echo "Message Body" | mail -s "Subject Line" -a attachment.txt email@domain

Install mail command in Centos/RHEL

sudo yum install mailx

Install mail command on Ubuntu/Debian/LinuxMint

sudo apt-get install mailutils

Upvotes: 2

Related Questions