Flethuseo
Flethuseo

Reputation: 6189

emailing scripts

Trying to send mail with the following script, I substitute $1 with the email address I want to send the email to.

#!/bin/bash
# script to send simple email
# email subject
SUBJECT="SET-EMAIL-SUBJECT"
# Email To ?
EMAIL="$1"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE

I have tried sending myself emails with this script, but I don't get anything. I also don't get an error which makes it more difficult to figure out what's wrong. Anyone know how to send an email through a script? I'm on a macbook pro, and my operating system is Leopard.

Ted.

Upvotes: 0

Views: 246

Answers (1)

superfro
superfro

Reputation: 3302

(worth a shot to try another method)

cat $EMAILMESSAGE | mail -s "$SUBJECT" "$EMAIL"

But other reasons you aren't getting the email could possibly be that, whomever /bin/mail is passing the email off to is never making it to the server. See if you have the mailq command ?

Also, sometimes email's generated like this look really raw without a lot of headers and often get tossed into the spam folder.

Upvotes: 2

Related Questions