2

I'm trying to send a csv file as an attachment through the command line in Ubuntu. Currently, when running what seems to be the right command an e-mail is sent however, the contents of the CSV file are sent in the body instead of an actual file.

Any ideas? The command used is:

mailx -a ./filename email@address.co.uk
terdon
  • 98,183
  • 15
  • 197
  • 293
fiverivers
  • 23
  • 4

2 Answers2

1

You can use the command mutt for this purpose

mutt -s "Test mail" -a /tmp/file.tar.gz -- you@domain.com < /tmp/mailmessage.txt

Where /tmp/file.tar.gz is the attachment and /tmp/mailmessage.txt is the content of mail

aneeshep
  • 29,975
  • 14
  • 64
  • 77
  • I get an error saying unable to attach file. – fiverivers Sep 18 '14 at 11:18
  • Can't stat SOMEONE@SOMETHING.CO.UK: No such file or directory SOMEONE@SOMETHING.CO.UK: unable to attach file. – fiverivers Sep 18 '14 at 11:24
  • @fiverivers Sorry, I missed '--' in the command. Updated my answer. please check it – aneeshep Sep 18 '14 at 11:28
  • Hey dude,Thanks for your help however, after using that command I am moved to an interactive UI which asks me to specify things like the body/subject etc etc and then I have to manually press y to send the file. Is there anyway to send an attached csv file via email with one command, completely autonomously. Thanks – fiverivers Sep 18 '14 at 11:32
  • @fiverivers yes provide the missing things to the command line (mutt will prompt for missing parts). – Rinzwind Sep 18 '14 at 11:43
  • @fiverivers can you copy/paste the command you tried? The above command works for me.Yes, completely autonomously – aneeshep Sep 18 '14 at 12:14
1

the code I used

mail --subject="what ever" --attach=foo.csv me@me.com <<foobarbaz

mail with file

foobarbaz

with

  • --attach specifying the file to be send
  • <<foobarbaz is syntax for an here document (i.e. will send to mail all data up to a line begining with foobarbaz )

Edit:

from man mailx

  • -a, --append=HEADER: VALUE append given header to the message being sent
  • -A, --attach=FILE, attach FILE
Archemar
  • 662
  • 8
  • 21