By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,775 Members | 1,132 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,775 IT Pros & Developers. It's quick & easy.

Send mail via shell script

krik
P: 1
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 :

Expand|Select|Wrap|Line Numbers
  1. myserver> mail -s 'test mail' destination@test.org
  2. ~R reply.here@test.org
  3. content of the message
  4. .
  5. EOT
This works fine, the reply-to is correctly set. Now, the script I wrote :


Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/bash
  2. cat << EOF | mail -s 'test mail' destination@test.org
  3. ~R reply.here@test.org
  4. content of the message
  5. 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
Oct 26 '07 #1
Share this Question
Share on Google+
2 Replies

P: 54
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 :

Expand|Select|Wrap|Line Numbers
  1. myserver> mail -s 'test mail' destination@test.org
  2. ~R reply.here@test.org
  3. content of the message
  4. .
  5. EOT
This works fine, the reply-to is correctly set. Now, the script I wrote :


Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/bash
  2. cat << EOF | mail -s 'test mail' destination@test.org
  3. ~R reply.here@test.org
  4. content of the message
  5. 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
Dec 3 '07 #2

P: 1
try option -I

Expand|Select|Wrap|Line Numbers
  1.       #!/usr/local/bin/bash
  2.       mail -I -s 'test mail' toto@toto.com <<EOF
  3.       ~R toto1@toto.com
  4.       content of the message
  5.       EOF
  6.  

question:

does tilde escape ~R exist?????

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

i would appreciate your comments
Jul 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.