Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  52] [ 0]  / answers: 1 / hits: 168908  / 1 Year ago, sun, may 28, 2023, 5:37:18

How can I make crontab email me with the output of its jobs? I have [email protected] above the jobs, but it doesn't work.



I know I need to use something like Postfix or Sendmail but for the life of me I cannot find out how to achieve this. I've searched and searched for a simple guide on setting up Postfix but they're all insanely complicated and expect you to be setting up a whole server to send and receive email and to know all the terms (like, what is a domain name for outgoing emails?).



All I want to do is have crontab email me. Why is this so difficult??



Additional Info:



My crontab file looks like this:



[email protected]
1 0 * * * ~/Desktop/toskymesh.sh
59 6 * * * ~/Desktop/tooptus.sh
0 3 * * * snapraid sync


More Additional Info:



The output of ps -ef | grep '[s]endmail'



root 6840 1370 0 10:26 ? 00:00:00 sendmail: MTA: accepting connections


I know for sure cron is working, but I'm testing the mail command with echo Test | mail -s Test [email protected] anyway.


More From » email

 Answers
5

In the end I used sSMTP. It's far simpler than either Postfix or sendmail and does the job beautifully.


For future reference, here's how to use sSMTP with Yahoo Mail (don't worry, it's a lot less complex than it looks):



  • Use your package manager to download ssmtp. I used Synaptic, but sudo apt-get install ssmtp should work as well.



  • Open the config file at /etc/ssmtp/ssmtp.conf.



  • Make the config look like this:


    [email protected]       <--- Use your real email here
    mailhub=smtp.mail.yahoo.com:587 <--- This will depend on your email provider
    FromLineOverride=YES
    UseSTARTTLS=YES
    [email protected] <--- Use your real email here
    AuthPass=yourRealYahooPassword <--- Use your real email password here
    TLS_CA_File=~/cert.pem


  • Create the cert.pem file with OpenSSL. I used openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 9999 -nodes (more info at How to create a self-signed certificate with OpenSSL). You can stick the file anywhere, but I just chucked it in ~/. Wherever you put it, make sure you point the TLS_CA_File= line in ssmtp.conf to the correct location.



  • Open the file /etc/ssmtp/revaliases and add the line (replacing the appropriate sections with your details):


    yourPCUsername:[email protected]:smtp.mail.yahoo.com:587

    If you're running as root, I assume you would need to add another line replacing your name with 'root'.



  • That's it, you're good to go! To test, the easiest way (IMO) is to create a file with the following in it:


    To: [email protected]                       <--- Use your real email here...
    From: "whateverYaWant" <[email protected]> <--- ...and here
    Subject: Some Notifying Email
    MIME-Version: 1.0
    Content-Type: text/plain

    Body of your email goes here. Hello world!


  • Check that you don't have the real sendmail installed by running sendmail -V. It should say 'sSMTP'.



  • Finally, run cat fileWithEmailInIt.txt | sendmail -i -t, then wait a few seconds (10-30) and check your email!




Additional note 1: If you have trouble with Gmail, try option 1 of this answer.

(Thanks to Ben Creasy!)


Additional note 2: If mail is sending from the command line but not through crontab, try changing FromLineOverride to NO in /etc/ssmtp/ssmtp.conf. You can also get more detailed logging by adding Debug=YES to ssmtp.conf - the extra logging goes to /var/log/mail.log.

(Thanks Jakub Kukul!)


[#22842] Sunday, May 28, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
quivedge

Total Points: 223
Total Questions: 116
Total Answers: 124

Location: Slovenia
Member since Wed, Apr 6, 2022
2 Years ago
;