0

I'm trying to send an email from a bash script but when I run the script it completes without any errors but the email doesn't seem to be sending (it doesn't arrive in my inbox at least)

SUBJECT="SET-EMAIL-SUBJECT"
EMAIL="[email protected]"
EMAILMESSAGE="/home/me/workspace/ss/UI/UI/legacy/Output.txt"
echo "This is an email message test">$EMAILMESSAGE
echo "This is a second line">>$EMAILMESSAGE
echo "This is a third line">>$EMAILMESSAGE
# send an email using /bin/mail
`/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE`

Thanks

3
  • 1
    And sending email by mail command manually works? Are you positively running a MTA, such as exim4, postfix or sendmail - and is it correctly configured? Commented Feb 10, 2012 at 9:55
  • Try to send mail to local user like root or your username. Then run the mail command as this user. This will allow you to check if local delivery works even if sending mail to the internet is not setup correctly. I've not tested it but your script looks okay. Commented Feb 10, 2012 at 10:19
  • Thanks for the help guys, turns out we're not allowed to send mail from the server anymore as it resulted is us being black listed a couple of times, making this irrelevant Commented Feb 10, 2012 at 10:40

2 Answers 2

3

Aside from the limitation that what you're trying to do has been blocked, your error is the backticks on the last line of your script. /bin/mail is a command just like echo. What you're trying to do is to execute the mail command and then execute the output of the mail command.

Sign up to request clarification or add additional context in comments.

Comments

-1

I created a function which I used in a script. You may vary it as you wish.

send_mail(){
     printf "<what you want to say>  %s <what you want to say>  %d \n" <another function> <another function>| ${MAIL} -s "${SBJCT}" ${EMAIL}
}

Where:

MAIL=`which mail`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.