I have a Bash Script to send email which is excuted via Kubernetes CronJob but when the job runs the email is not being sent as in the error log below :
kubectl -n labs logs send-mail-28210503--1-grtpv
bin dev mail.sh etc home lib media mnt opt proc root run sbin srv sys tmp usr var
Starting-MAILSEND
bin dev mail.sh etc home lib media mnt opt proc root run sbin srv sys tmp usr var
mail: Field already retained: from
mail: No such file to load: /root/.mailrc
mail: Warning -- v15-compat=yes will be default in v14.10.0!
mail: P(seudo)R(andom)N(umber)G(enerator): *TLS RAND_*
mail: smtp=mail2.mycompany.com:25 contains invalid byte ':'
/root/dead.letter 10/269
sendmail: can't connect to remote host (127.0.0.1): Connection refused
/root/dead.letter 10/269
mail: ... message not sent
Failed to send the email
UPDATE
This is how the Bash script looks like after changes (will reintroduce error checking later):
#!/bin/sh
# Function to send an email notification
echo ******************************************************
echo Starting-MAILSEND
echo ******************************************************
echo -e "This is a Email test." | mailx -v -s "Job Failed" -r "ops@mycompany.com" jonhdoe@mycompany.com -S "smtp=mail2.mycompany.com"
I have removed port from the SMTP server value but I am facing a new error which seems to suggest that its an invalid value:
bin dev email.sh etc home lib media mnt opt proc root run sbin srv
sys tmp usr var
Starting-MAILSEND
bin dev email.sh etc home lib media mnt opt proc root run sbin srv sys tmp usr var
mail: Field already retained: from
mail: No such file to load: /root/.mailrc
mail: Warning -- v15-compat=yes will be default in v14.10.0!
mail: P(seudo)R(andom)N(umber)G(enerator): *TLS RAND_*
mail: smtp=mail2.mycompany.com is an invalid alias name
/root/dead.letter 10/268
sendmail: can't connect to remote host (127.0.0.1): Connection refused
/root/dead.letter 10/268
mail: ... message not sent
Failed to send the email.
The Bash script is bundled with the following Dockerfile below and the Docker image is used in a K8s CronJob resource:
FROM dockette/alpine:3.11
COPY mail.sh .
RUN chmod +x mail.sh
RUN apk update && \
apk upgrade && \
apk add --no-cache s-nail && \
ln -s /usr/bin/mail /usr/bin/mailx && \
rm -rf /var/cache/apk/*
CMD ["/usr/bin/mailx"]
NB: The mail credentials are valid because I am able to send emails using the same paramaters (sender, smtp server,recipient), only difference is that this is via a Prometheus AlertManagerConfig.
What am I missing ?