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
[email protected]
AuthPass=mypassword
UseSTARTTLS=YES

I then build and send a mail in a bash script:

#!/bin/sh -x
sender="[email protected]"
recipient="[email protected]"
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 <[email protected]> -S [email protected] -a /home/.../results/file.zip [email protected]

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 [email protected] 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.

1 Answer 1

0

The issue was resolved by using the mutt mail client.

The mail.sh script file, when called by the Jenkins job, does send the mail, and I receive it in my mail box.

#!/bin/bash

sender="[email protected]"

recipient="[email protected]"

zipfile="/home/.../file.zip"

today=`date +\%d-\%m-\%Y`

mailSubject="The subject "$today

mailBody=$(cat /home/.../mail-body.html)
mailBody="${mailBody/\$today/$today}"

echo "$mailBody" | mutt -s "$mailSubject" -e "set content_type=text/html" -e "my_hdr From:My Name <$sender>" -a "$zipfile" -- $recipient

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .