0

I'm having trouble sending an email using bash and sendmail on Amazon Linux. In my bash script I have

    echo "Subject: My subject" >> /tmp/email.txt
    echo "" >> /tmp/email.txt
    cat /tmp/out.txt >> /tmp/email.txt
    sendmail $EMAIL_ON_FAILURE < /tmp/email.txt

Note that the body of my email should be the contents of /tmp/out.txt. Despite teh fact I have verified through echo that "$EMAIL_ON_FAILURE" is not empty, I'm not finding any emails in my inbox (or spam folders). Is there somethign wrong with the above or is there another way I can check on my system that the email was actually sent?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • Send you message in verbose mode: `sendmail -i -v $EMAIL_ON_FAILURE < /tmp/email.txt` (-i turns off "single dot line is end of message) – AnFi May 01 '17 at 16:46
  • Did you verify that the host, where you are running this command, is configured to properly route e-mails? – alvits May 01 '17 at 23:02

1 Answers1

0

Sendmail is a Mail-transport-agent; you need a mail-user-agent; Try using the 'mail' command, i.e.

mail -s "${SUBJECT}" ${EMAIL_Address} < ${FILE}

From the man page:

Sendmail is not intended as a user interface routine; other programs provide user-friendly front ends; sendmail is used only to deliver pre-formatted messages.

:)
Dale

Dale_Reagan
  • 1,953
  • 14
  • 11
  • That will not work either if the OP has no smtp relay. Your solution is under the assumption that a working smtp relay is in place. – alvits May 01 '17 at 23:04
  • Don't get me wrong. I totally understand your answer. My comment is based on the analysis of the OP's post. I agree that `sendmail` is not a friendly front end tool, but it should still work if the system is configured correctly. Because it didn't work, hence my comment that probably the system doesn't support sending emails. If you don't feel comfortable with my constructive comment, please say so and I will gladly remove it. – alvits May 03 '17 at 00:41