0
I installed and configured a mail client:
sudo apt-get install heirloom-mailx
sudo vi /etc/ssmtp/ssmtp.conf
mailhub=smtp.mail.yahoo.com:587
FromLineOverride=YES
AuthUser=myuser@yahoo.com
AuthPass=mypassword
UseSTARTTLS=YES
I then build and send a mail in a bash script:
#!/bin/sh -x
sender="myuser@yahoo.com"
recipient="recipient@domain.com"
zipfile="results/file.zip"
today=`date +\%d-\%m-\%Y`
mailSubject="My subject on the "$today
mailBody="Les résultats de la fiabilisation des données du $today sont dans le fichier zip.\n\nMy-Company"
echo $mailBody | mail -s "$mailSubject" -r "My Company <$sender>" -S replyto="$sender" -a $zipfile $recipient
A crontab job does send the mail and I receive it in my mailbox:
05 12 * * * /home/.../script.sh
But a Jenkins job does not seem to send it, I receive nothing in my mail box:
/home/.../script.sh > logs/script.log 2>&1
The script.log shows the mail command being called:
+ mail -s My subject -r My Company <???@my-domain.com> -S replyto=???@my-domain.com -a /home/.../results/file.zip ???@my-domain.com
I edited out the sensitive data.
The Jenkins job shows a successful blue ball for the job.
Another thing to note is that, when using crontab and receiving the email in my company mail box, the email address of gmail used to log on smtp also receives an email complaning about:
Address not found
Your message wasn't delivered to root@my-domain.com because the address couldn't be found. Check for typos or unnecessary spaces and try again.
UPDATE: If instead of buildng the mail in a script.sh
bash script and having Jenkins execute this bash script, I have Jenkins directly build the mail, then the mail is sent and I receive it in my mail box.