Send mail via shell script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krik
    New Member
    • Oct 2007
    • 1

    Send mail via shell script

    Hello,

    I would like to send a mail via a script with customized From field or at least with Reply-To. This email is sent by a monitoring server via a cron job and the users should see this mail as coming from the group mailbox I belong to.

    I haven't been able to find how to send a mail with a different address in the From but from the command line I can change the Reply-to (better than nothing). If I use the same in a script it doesn't work... Here is what I did :

    Code:
    myserver> mail -s 'test mail' destination@test.org
    ~R reply.here@test.org
    content of the message
    .
    EOT
    This works fine, the reply-to is correctly set. Now, the script I wrote :


    Code:
    #!/usr/local/bin/bash
    cat << EOF | mail -s 'test mail' [email]destination@test.org[/email]
    ~R [email]reply.here@test.org[/email]
    content of the message
    EOF
    With this script I receive the mail with the ~R line in the body and the reply-to is not set...

    Any idea why this behaviour? Any idea how to set the from field?

    Thanks,
    Krik
  • ramadeviirrigireddy
    New Member
    • Jul 2007
    • 54

    #2
    Originally posted by krik
    Hello,

    I would like to send a mail via a script with customized From field or at least with Reply-To. This email is sent by a monitoring server via a cron job and the users should see this mail as coming from the group mailbox I belong to.

    I haven't been able to find how to send a mail with a different address in the From but from the command line I can change the Reply-to (better than nothing). If I use the same in a script it doesn't work... Here is what I did :

    Code:
    myserver> mail -s 'test mail' destination@test.org
    ~R reply.here@test.org
    content of the message
    .
    EOT
    This works fine, the reply-to is correctly set. Now, the script I wrote :


    Code:
    #!/usr/local/bin/bash
    cat << EOF | mail -s 'test mail' [email]destination@test.org[/email]
    ~R [email]reply.here@test.org[/email]
    content of the message
    EOF
    With this script I receive the mail with the ~R line in the body and the reply-to is not set...

    Any idea why this behaviour? Any idea how to set the from field?

    Thanks,
    Krik

    Use mailx command. Example:
    mailx -s "Subject" mail-id's to send < file.txt

    Comment

    • rhXX
      New Member
      • Jun 2007
      • 1

      #3
      try option -I

      Code:
            #!/usr/local/bin/bash
            mail -I -s 'test mail' toto@toto.com <<EOF
            ~R toto1@toto.com
            content of the message
            EOF

      question:

      does tilde escape ~R exist?????

      i didn't find it, and my mail / mailx doesn't recognize it ?????

      i would appreciate your comments

      Comment

      Working...