0

I'm trying to send an email using shell command in my ruby script. I use command

%x{echo "sometext" | mail -s "Account report #{file_tmp}" -a /home/linux/reports/#{file} #{address[0]}}

and I get

Send options without primary recipient specified. Usage: mail -eiIUdEFntBDNHRVv~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users sh: line 2: send_report@gmail.com: command not found

Why an email address is taken as second line of command and how to fix it?

mila002
  • 327
  • 3
  • 14

1 Answers1

0

Try stripping newlines on the file variable:

%x{echo "sometext" | mail -s "Account report #{file_tmp}" -a /home/linux/reports/#{file.strip} #{address[0]}}
Derek Wright
  • 1,452
  • 9
  • 11
  • It works, thanks! But now it sends an email with attachment content in body message. Using this command directly in command line it sends as normal attachment. Why? – mila002 May 09 '17 at 13:14
  • http://stackoverflow.com/questions/17359/how-do-i-send-a-file-as-an-email-attachment-using-linux-command-line/14213935#14213935 you may need to structure the command a bit differently and use uuencode. – Derek Wright May 09 '17 at 13:22