This is how I try to send, email with sendmail command.

echo "Dear user,

please find the attached file.

Support team " | mailx -s "x12 extract for 837 transaction" -a $LogFilePath/file.csv $email_id 

but i am getting the error as "-a illegal operation" checked with man mailx command there is no flag like -a and there flag for attachment.

so I have tried with sendmail command

echo $email_id
#From: $email_from_recipients
echo "MIME-Version: 1.0"
echo "Content-Type: text/html; charset=us-ascii"   
echo Subject: Report

) | /usr/lib/sendmail -t

it was not sending the file as attachment.

the contents of the csv file is displayed in the body of the mail with comma separated one.

how to send the attachment with sendmail command in unix?

  • Have you try cat $LogFilePath/file.csv instead of just $LogFilePath/file.csv? – Romeo Ninov May 3 '18 at 6:32
  • tried with that too getting contents of the csv file is didplayed in the body of the email with comma separated one – Kalishwari May 3 '18 at 7:11
  • 3
    To help clarify what mailx implementation you have, let us know what Unix you are using. – Kusalananda May 3 '18 at 7:41
  • If you're writing directly to sendmail you need a blank line after your headers. – roaima May 5 '18 at 20:59

For example echo test | mail -s "Subj" "someemail@gmail.com" --attach=/home/someuser/test.txt

  • 1
    As it is mentioned in the headline we talk about UNIX and there mail do not have --attach – Romeo Ninov May 3 '18 at 6:31
  • 1
    it's not working – Kalishwari May 3 '18 at 7:17
  • it sending mail but the attachment is missing it shows /home/coe_users/dead.letter... Saved message in /home/coe_users/dead.letter – Kalishwari May 3 '18 at 7:19

Try with the -A option; turns out that -a is the flag for appending headers whereas -A is the flag for sending attachments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.