Koozali.org: home of the SME Server

Obsolete Releases => SME Server 7.x => Topic started by: basmistry on August 23, 2008, 12:54:58 AM

Title: Command line mail
Post by: basmistry on August 23, 2008, 12:54:58 AM
How do I attach file using command line mail

I've used Suse Linux in before and it has a "-a" option to attach a file

eg.
echo Test Completed at `date` | mail -s "Test email" -a /home/test.log  me@mydomain.com

(date is set at top of the script)

Title: Re: Command line mail
Post by: cactus on August 23, 2008, 10:13:17 AM
How do I attach file using command line mail

I've used Suse Linux in before and it has a "-a" option to attach a file

eg.
echo Test Completed at `date` | mail -s "Test email" -a /home/test.log  me@mydomain.com

(date is set at top of the script)


mail is not installed, instead mutt is, there is a bash one-liner on how to send mail with that from the command line here: http://www.cyberciti.biz/tips/sending-mail-with-attachment.html
Title: Re: Command line mail
Post by: basmistry on August 23, 2008, 12:07:01 PM
Mail is installed

the does not support attachments ie. have a -a option

I can send an emal

echo Test Email from SME | mail me@mydomain.com -s "This is a test from SME"
Title: Re: Command line mail *** SORTED **
Post by: basmistry on August 23, 2008, 01:29:48 PM

I've sorted it myself...

My file is a Text file so ...

echo Test Completed at `date` | mail -s "Test email" -a /home/test.log  me@mydomain.com < /home/mytextfile.txt

Title: Re: Command line mail *** SORTED **
Post by: CharlieBrady on August 23, 2008, 04:55:19 PM
I've sorted it myself...

My file is a Text file so ...

echo Test Completed at `date` | mail -s "Test email" -a /home/test.log  me@mydomain.com < /home/mytextfile.txt



Mail only has one "standard input". You can't do pipe and also redirect from a file. If you want both text in your mail, you need to do:

Code: [Select]
( echo Test Completed at $(date); cat /home/mytextfile.txt ) | mail -s "Test email" me@mydomain.com

$(...) has various advantages over backticks and is recommended syntax these days.