LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   sendmail subject configuration (https://www.linuxquestions.org/questions/linux-general-1/sendmail-subject-configuration-603900/)

yusufs 12-02-2007 06:43 AM

sendmail subject configuration
 
Hai all,

I've configured sendmail in my Linux machine and it is working fine and am sending mail like :


echo "Test" | sendmail -v oracle@ora.com.su

the mail is delivered successfully with the content Test.. how can I add subject to this mail.. such that the mail should get deliver with
the subject.

Please guide
Yusuf

unSpawn 12-02-2007 07:06 AM

'echo "Subject: Test" | /usr/sbin/sendmail -t user@host' should work, however using "mail" from the mailx or mail-utils package will be easier ('/bin/true| mail -s "Test" user@host'). If you're going to send attachments from the CLI or a shellscript later on search for "mpack".

yusufs 12-03-2007 01:20 AM

unspawn
 
Quote:

Originally Posted by unSpawn (Post 2977438)
'echo "Subject: Test" | /usr/sbin/sendmail -t user@host' should work, however using "mail" from the mailx or mail-utils package will be easier ('/bin/true| mail -s "Test" user@host'). If you're going to send attachments from the CLI or a shellscript later on search for "mpack".




Hai ,

Thanks for the guidance.. above works fine.. but how to add message body ..I want to have both subject and body message for the same.



'echo "Subject: Test" | /usr/sbin/sendmail -t user@host'


it works fine.. where I can add the message of the mail. please guide

Yusuf

unSpawn 12-03-2007 10:27 AM

'(echo "Subject: Test"; echo; cat /etc/hosts) | /usr/sbin/sendmail -t user@host'

yusufs 12-04-2007 06:34 AM

Quote:

Originally Posted by unSpawn (Post 2978604)
'(echo "Subject: Test"; echo; cat /etc/hosts) | /usr/sbin/sendmail -t user@host'



Thanks unspawn for your answer, I did the following as u said :


oracrp@oracle test]$ cat alert.sh
#!/bin/sh
# Script used to monitor the database alert log file
RETURN_CODE=`grep ORA-* /d02/oracle/oracrp/proddb/9.2.0/admin/DEV_oracle/bdump/alert_DEV.log | wc -l`
if [ $RETURN_CODE -eq 0 ]
then
exit 0
else
'(echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log)' | /usr/sbin/sendmail erp_webmail@ali.com.kw

exit 1
fi



am getting the error :

alert.sh: line 8: (echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log): command not found

Guide please

Yusuf

colucix 12-04-2007 08:20 AM

Code:

(echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log")
Don't put quotes around this code and it should work. If running from a script you can also consider a more readable "here document", as in
Code:

/usr/sbin/sendmail user@host << EOM
From: Colucix
To: user@host
Subject: Test

$(date)
$(echo "DEV - There are $RETURN_CODE errors in Alert log)
$(any_other_command)

Some text here.
Bye
EOM

The first part of the input to sendmail is to fill the various fields of the e-mail, the rest goes into the mail body.

yusufs 12-04-2007 03:29 PM

Quote:

Originally Posted by colucix (Post 2979763)
Code:

(echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log")
Don't put quotes around this code and it should work. If running from a script you can also consider a more readable "here document", as in
Code:

/usr/sbin/sendmail user@host << EOM
From: Colucix
To: user@host
Subject: Test

$(date)
$(echo "DEV - There are $RETURN_CODE errors in Alert log)
$(any_other_command)

Some text here.
Bye
EOM

The first part of the input to sendmail is to fill the various fields of the e-mail, the rest goes into the mail body.

Thanks Colucix, thats worked fine.. sorry to bother you again.can u please tell me how to add date with the current time to the subject
such that it should display the subject test with time

(echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log").

am executing the script with sh in the line it sends mail to the user
where as when I add it to the cron .. it does'nt work .. any idea colucix ?..How I can fix it ?

user is added to cron.allow and no users are in cron.deny
cornd is runniing..


Thanks for your patience and guidance
Yusuf

colucix 12-05-2007 03:46 AM

Quote:

Originally Posted by yusufs (Post 2980184)
Thanks Colucix, thats worked fine.. sorry to bother you again.can u please tell me how to add date with the current time to the subject such that it should display the subject test with time

You're welcome! And don't worry, you don't bother me. You can add date to the subject in the same way you use command substitution in the mail body, e.g.
Code:

Subject: $(date +%d-%b-%Y) - any other text here
The idea is: you're running the sendmail command from a shell, and as for any other command the shell expands variables, does command substitutions and so on... before actually executing the given commands. In this way you can put any shell variable, or any command substitution inside the "here document" which represents the mail to be sent: the shell takes care of building the text and pass it as input to sendmail. For an explanation of "here documents" you can see Chapter 18 of the Advanced Bash Scripting Guide.

Regarding your other issue about the cron job, I'm following the other thread of yours and... it's puzzling me! Bye.

yusufs 12-06-2007 03:29 AM

Quote:

Originally Posted by yusufs (Post 2980184)
Thanks Colucix, thats worked fine.. sorry to bother you again.can u please tell me how to add date with the current time to the subject
such that it should display the subject test with time

(echo "Subject:Test"; echo "DEV - There are $RETURN_CODE errors in Alert log").

am executing the script with sh in the line it sends mail to the user
where as when I add it to the cron .. it does'nt work .. any idea colucix ?..How I can fix it ?

user is added to cron.allow and no users are in cron.deny
cornd is runniing..


Thanks for your patience and guidance
Yusuf

Thanks Colucix.. that helped me out.


Yusuf


All times are GMT -5. The time now is 09:09 AM.