Find the answer to your Linux question:
Results 1 to 5 of 5
how do i email a file from one person to another in bash? I know there is a mail command and i tried Code: mail email_address < file and this ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2005
    Posts
    99

    sending email in bash


    how do i email a file from one person to another in bash? I know there is a mail command and i tried
    Code:
    mail email_address < file
    and this didnt produce an error but didnt send the email either. How do i use the mail command?

  2. #2
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Location
    Maryland, USA
    Posts
    510
    That should work. I just experimented with something similar, which works for me:
    Code:
    echo 'This is a test.' | mail -r me@mine -s 'A test' me@myother
    -r specifies the from address, -s specifies the subject. And of course I used real email addresses.

    This test also revealed that I had errors in my ~/.mailrc file (which contains aliases for email addresses) because the 'mail' command griped about them.

  3. #3
    Just Joined!
    Join Date
    Sep 2005
    Posts
    99
    i tried that and i get an error it says
    mail: options MUST PRECEDE persons
    Also, i assume that sends the stuff in ' ' right? I want to send the contents of a file. It has something to do with the file being empty i think because when i tried to send an empty file using
    mail email_address < file it does not print an error, however it doesn't deliver the message either. But if i do that same command: mail email_address < file and the file is not empty then it gives the erorr message and sometimes the error message reads:
    exec failed. errno=2.
    mail: ERROR signal 13
    Any ideas?

  4. #4
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Location
    Maryland, USA
    Posts
    510
    errno 2 is ENOENT, "No such file or directory". Are you sure you typed the file right?

    Redirecting from a file like you did should be exactly the same as piping echo like I did. But It sounds like you can't send an empty mail message.

    I'm using the mail program on Mandriva, which is actually 'nail', which I guess is now known as Heirloom mailx. Hopefully different versions work the same.

  5. #5
    Just Joined!
    Join Date
    Sep 2005
    Posts
    99
    well when it was empty there was no error message but the message still didn't send. However, i get the error message if i try to mail with a file that is not empty.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •