1748150 Members
3677 Online
108758 Solutions
New Discussion юеВ

Re: 'mail' syntax

 
SOLVED
Go to solution
Michal_6
Occasional Contributor

'mail' syntax

Hi.
I configured my sendmail last time and now I want it to send me mail's with somemessages when something happens. Now (that'a an example) I want to put into cron a command thet will send to me every hour a message with the subject "MAIL SUBJECT" and the text "THIS IS A CRON MESSAGE". What will be the 'mail' command syntax?

mail user@server.xx -s "MAIL SUBJECT" "THIS IS A CRON MESSAGE"

doesn't want to work.
Thanks for your help.
5 REPLIES 5
Tom Maloy
Respected Contributor
Solution

Re: 'mail' syntax

echo "This is a cron message" | mailx -s "mail subject" user@server

Note use of mailx instead of mail.

HTH

Tom
Carpe diem!
RAC_1
Honored Contributor

Re: 'mail' syntax

mailx -s "Subject" yy@yy.com < file

contents of file mailed to user yy@yy.com with mail subject line as Subject
There is no substitute to HARDWORK
Dennis Chow
New Member

Re: 'mail' syntax

These 2 commands can only send the file content inside the mail. But how to send a mail with an attachment?

Tks
denden
Tom Dawson
Regular Advisor

Re: 'mail' syntax

Kropeck,

I copied this script off the forum some time back. I think it was posted by Steven Burgess.

I apologize if I have the credit incorrect.

Tom
----------------------------

#!/usr/bin/sh

export EMAIL_TO=username@receiving.email
export EMAIL_FROM=username@sending.email
export EMAIL_SUBJECT="subject of e-mail"
export EMAIL_BODY=/tmp/body_of_e-mail
export FILE_NAME=filename.txt
export ATTACHED_FILE=/tmp/file_to_attach

{
echo To: $EMAIL_TO
echo From: $EMAIL_FROM
echo Subject: $EMAIL_SUBJECT
echo 'MIME-Version: 1.0'
echo 'Content-type: multipart/mixed; boundary="xxxxyyyzzqzzyyyxxxx"'
echo '--xxxxyyyzzqzzyyyxxxx'
echo ''
cat $EMAIL_BODY
echo '--xxxxyyyzzqzzyyyxxxx'
echo 'Content-Disposition: attachment; filename="'$FILE_NAME'"'
echo ''
cat $ATTACHED_FILE
echo '--xxxxyyyzzqzzyyyxxxx--'
} | /usr/sbin/sendmail $EMAIL_TO
Deshpande Prashant
Honored Contributor

Re: 'mail' syntax

HI
#echo "THIS IS A CRON MESSAGE" |mailx -m -s "MAIL SUBJECT" user@server.com

Thanks.
Prashant.
Take it as it comes.