My mountain:
When I do a command from the cli such as: echo "body stuff" | mailx -s "subjecthere" -a "path/to/picturefile.jpg" myemail@gmail.com Everything works just fine and it is sent. Even when I echo all of the arguments from my bash script, copy and paste it into a new mailx command in the cli, it works. When I just run the bash command, I get:
Send options without primary recipient specified.
Usage: mailx -eiIUdEFntBDNHRV~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users
My boulder:
Code: Select all
#!/bin/bash
#get flag values
while getopts p:v: option
do
case "${option}"
in
p) PICTUREPATH=${OPTARG};;
v) VIDEOPATH=${OPTARG};;
esac
done
#Destination e-mail addresses
CELLTO="myemail@gmail.com"
EMAILTO="myotheremail@yahoo.com"
ARGS='-s "Motion detected" '
#check files exist before checking times
PICFILE='/home/bulsatar/.motion/lastpic.txt'
VIDFILE='/home/bulsatar/.motion/lastvid.txt'
if [[ ! -e "${PICFILE}" ]]
then
touch "${PICFILE}"
fi
if [[ ! -e "${VIDFILE}" ]]
then
touch "${VIDFILE}"
fi
NOW=$(date +"%Y%m%d%H%M%S")
#check for pic first
if [[ ! -z "${PICTUREPATH}" ]]
then
#check if time frame is greater than (-gt) than 20 seconds
PICLINE=$(head -n 1 "${PICFILE}")
if [[ ! -z "${PICLINE}" ]]
then
if [[ $((${NOW} - ${PICLINE})) -gt 20 ]]
then
echo ${NOW} > ${PICFILE}
ARGS+=' -a "'"${PICTUREPATH}"'" '"${CELLTO}"
echo "${ARGS}"
echo 'take a look' | mailx "${ARGS}" <<<<<<<<this is where I am having trouble
fi
else
echo ${NOW} > ${PICFILE}
fi
fi
#check for vid next
if [[ ! -z "${VIDEOPATH}" ]]
then
#check if time frame is greater than (-gt) than 1 minute
VIDLINE=$(head -n 1 "${VIDFILE}")
if [[ ! -z "${VIDLINE}" ]]
then
if [[ $((${NOW} - ${VIDLINE})) -gt 60 ]]
then
echo ${NOW} > ${VIDFILE}
ARGS+=' -a "'"${VIDEOPATH}"'" '"${EMAILTO}"' < "/home/bulsatar/bin/Motion\ Setup\ Files/msg.txt"
echo "${ARGS}"
mailx "${ARGS}" <<<<<<<<this is where I am having trouble
fi
else
echo ${NOW} > ${VIDFILE}
fi
fi
Code: Select all
.mailrc
set smtp-use-starttls
set ssl-verify=ignore
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=myemail@gmail.com
set smtp-auth-password=mypassword
set from="myemail@gmail.com"
.msmtprc
#Gmail account
defaults
logfile ~/msmtp.log
account gmail
auth on
host smtp.gmail.com
from myemail@gmail.com
auth on
tls on
tls_trust_file /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt
user myemail@gmail.com
password mypassword
port 587
account default : gmail
http://www.fclose.com/1411/sending-emai ... ails-smtp/
http://tuxtweaks.com/2012/10/send-gmail ... mand-line/
Things I have tried so far:
as you can tell from the script, there are two different ways I am trying to set the body of the email, both with the same results
I have tried setting up postfix (everything that said "tutorial" was waaaayyy over my head to set that up)
I have tried setting up mutt (see above)
apparently ssmtp can't do attachments
mailutils (see postfix)
I am so close, please help!