Alex Rivera | Logout

Sending email using unix shell scripting

Asked 2009-11-23T09:23:08.790
9

I have to write a script to send mails using unix shell scripts.

The following script allows me to have variable message body.

Is it possible to have a variable subject part in the code below?

#!/bin/bash
# Sending mail to remote user

sender="root@sped56.lss.emc.com"
receiver="root@sped56.lss.emc.com"
body="THIS IS THE BODY"
subj="THIS IS THE SUBJECT."


echo $body | mail $receiver -s "THIS IS THE SUBJECT" // this works fine
echo $body | mail $receiver -s $subj // ERROR - sends one mail with only
//"THIS" as subject and generates another error mail for the other three words 
Edit
Report

1 Answer

3

you can use mailx and always put your quotes around variables

mailx -s "$subj" my.email@my.domain.com < myfile.txt
answered 2009-11-23T10:58:44.833

Your Answer