Setup cron job to send email to a bunch of people on a regular basis

75,221

Solution 1

First, see this post to see how you can send an email from terminal. Once you solved this problem and you can send emails from terminal, the following method should work to setup cron job to send emails.

Edit the crontab entries using crontab -e command (by default this will edit the current logged-in users crontab) and add the following line:

0 0 * * 1,3,5 $HOME/scripts/send_email.sh >> $HOME/tmp/out 2>&1

Now you should create send_email.sh script. Something like this:

#!/bin/bash

recipients="[email protected] [email protected] [email protected]"
subject="...Subject..."

cat $HOME/email_message | mail -s $subject $recipients

$HOME/email_message is the message (file) you want to send.

Don't forget to grant execute access for the script:

chmod +x $HOME/scripts/send_email.sh

Solution 2

If the recipe given in the links above for sending email from the terminal does not work for you right away, then setting up the right postfix configuration can be a pain. See sendEmail http://caspian.dotconf.net/menu/Software/SendEmail/ for a quick alternative solution.

Share:
75,221

Related videos on Youtube

PyariBilli
Author by

PyariBilli

Updated on September 18, 2022

Comments

  • PyariBilli
    PyariBilli over 1 year

    I want to send a fixed email reminder from my email address every Monday, Wednesday and Friday to a bunch of people.

    How do I go about setting this up using crontab?

    I have an email account on the mail server where I will setup the cron job, but the outgoing mails will be to gmail and hotmail accounts.

    • moon.musick
      moon.musick almost 11 years
      Try running echo 'test' | mail -s 'test' [email protected] (substitute the email address for something valid) from the terminal - if it works, you might use it as a basic method for sending notifications. There's a problem with gmail not providing whitelisting though, so you can't be sure it won't be filtered by spam filters. For the crontab part, you might package commands into a script and call it up from crontab or simply do 10 10 * * * echo 'message' | /usr/bin/mail -s 'subject' [email protected].
  • Eric Carvalho
    Eric Carvalho over 10 years
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.