0

I have a dev box using xubuntu 16.04. I have setup ssmtp to handle mail and can send email. I tested it with

 mail myemail@mydomain.com < .~/.bashrc' 

And it worked fine. I have a cron job running every minute which creates output that should get sent by my cron. 'grep CRON /var/log/syslog' gives me

 Sep 27 15:22:01 epdev CRON[19569]: (eventpuddle) CMD (cd /home/eventpuddle/eventpuddle/batch; ./scrape_check_todays_logs.bash )
 Sep 27 15:22:01 epdev sSMTP[19571]: Creating SSL connection to host
 Sep 27 15:22:01 epdev sSMTP[19571]: SSL connection using RSA_AES_128_CBC_SHA1
 Sep 27 15:22:03 epdev sSMTP[19571]: Sent mail for root@sun.prsc (221 2.0.0 Bye) uid=1000 username=eventpuddle outbytes=816

If i 'sudo -i' and type mail I am told there is no mail. /etc/ssmtp/ssmtp.conf is:

root=myemail@mydomain.com
mailhub=mail.myhoestingpeople.com:2525
hostname=sun.prsc
UseSTARTTLS=YES
AuthUser=user
AuthPass=password
FromLineOverride=YES
UseTLS=YES

cront entery is

* * * * *  ( cd /home/eventpuddle/eventpuddle/batch; ./scrape_check_todays_logs.bash ) 

./scrape_check_todays_logs.bash is

 #!/bin/bash 
 # scrape_check_todays_logs.bash (c) 2017 Ben Edwards (http://funkytwig.com/it)
 # Check logfiles for today and email them if there are any errors.

 . ~/.bashrc

 [ -z "$HOME" ]        && { echo '$HOME not set'; exit 1; }
 [ -z "$ADMIN_EMAIL" ] && { echo '$ADMIN_EMAIL not set'; exit 1; }

 t=/tmp/`basename $0 .bash`.$$.tmp
 d=$HOME

 grep -l "$d" log/*`date +%A`* > $t

 cat $t | while read line
 do
   echo "mail $line"
   mail -s "eventpuddle batch failuure $line" $ADMIN_EMAIL < $line
 done

 grep EXCLUD log/*`date +%A`* > $t

 mail -s 'eventpuddle exclusions' $ADMIN_EMAIL < $t

Not sure what other info to give but will if asked.

Ben Edwards
  • 425
  • 5
  • 18

1 Answers1

0

By the looks of it, it seems that you are trying to forward email to an external email address? SSMTP is used to forward alerts to an external email. Do you have SSMTP setup? The configuration (/etc/ssmtp/ssmtp.conf) should look like this

# The user that gets all the mails (UID < 1000, usually the admin)
root=username@gmail.com

# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable
# See also https://support.google.com/mail/answer/78799
mailhub=smtp.gmail.com:587

# The address where the mail appears to come from for user authentication.
rewriteDomain=gmail.com

# The full hostname.  Must be correctly formed, fully qualified domain name or GMail will reject connection.
hostname=yourlocalhost.yourlocaldomain.tld

# Use SSL/TLS before starting negotiation
UseTLS=Yes
UseSTARTTLS=Yes

# Username/Password
AuthUser=username
AuthPass=password
AuthMethod=LOGIN

# Email 'From header's can override the default domain?
FromLineOverride=yes

Ubuntu has a pretty good documentation on how to set it up - here

FELASNIPER
  • 327
  • 2
  • 9
  • I am using a external SMTP server and sending to an external email address. Ive used exactly this/etc/ssmtp/ssmtp.conf) on several machines to simply send cron output and other stuff that is sent to root to me. The reason i use ssmtp, and I think the reason a lot of other people use it, is so you don't have to setup a traditional mail services on the box. As I said I can send mail fine, its just sending it from cron that does not work, so ssmtp seems to be setup correctively. – Ben Edwards Sep 28 '17 at 19:38
  • What is your cron job? Can you paste it here? – FELASNIPER Sep 28 '17 at 21:40
  • added to question – Ben Edwards Sep 30 '17 at 15:44