CiviCRM, civimail cron job setup

To have your mailing actually send. We have to set up a cron job that will periodically poke CiviMail to send all of the mailings that are past their scheduled date.

Actually there are so many ways out there to do this thing, and probably are shorter, but I’ve built a script for my self to do that for me and is more clear to understand.

Note: The script works only with Drupal.

1. Create a file in /usr/local/bin/ called civicrmcron.sh
    and add the following lines in it, edit the required fields and save it:

#!/bin/sh

########################################################################################
#
# This script pokes CiviMail to send all the mailings that are past their schedule date.
# Make this script executable.
# Run this script from cron every 1 minute or every second (as you want).
# This script works only with Drupal.
# This script is tested and works...
#
########################################################################################

############################# EDIT ONLY THESE LINES ####################################

#
# Drupal user (Note: this user should have rights to work on CiviCRM)
#
drupalUser='USER'

#
# Drupal user's password
#
drupalUserPass='PASSWORD'

#
# Drupal/Civicrm site-key
# You can take it from: /sites/default/civicrm.settings.php
# on line:
# define( 'CIVICRM_SITE_KEY', 'SITE-KEY-HERE' );
#
civicrmSiteKey='SITE-KEY'

#
# Write sitename here in this case example: civicrm.example.com
#
siteName='civicrm.example.com'

############################################################################

civiurl="http://$siteName/sites/all/modules/civicrm/bin/civimail.cronjob.php"

echo ''
echo 'Your civimail.cronjob.php file is here: '
echo $civiurl

echo "Gathering your data..."
cividata="name=${drupalUser}&pass=${drupalUserPass}&key=${civicrmSiteKey}"
#echo $cividata

# Grouping all data in one place...
echo 'Grouping all data in one place ...'
allurl=$civiurl'?'$cividata

# Running the script...
echo 'Running the script...'
#echo "wget -O - -q $allurl"

# Executing the script
wget -O - -q $allurl

sleep 1

echo ''
echo "DONE !"
echo ''

2. After that change permissions to this file to a+x or +x

$ sudo chmod +x /usr/local/bin/civicrmcron.sh

3. Then create a file in /etc/cron.d named civicrm

$ sudo nano /etc/cron.d/civicrm

add the lines below lines to run the job every 5 minutes and save:

*/5 * * * *      root    /usr/local/bin/civicrmcron.sh > /dev/null
Advertisements

4 thoughts on “CiviCRM, civimail cron job setup

    1. Hi,
      I was using a localserver running Linux, so those are directories in my server.
      I am sorry if you are using Windows, unfortunately I don’t know how it is done there so I cannot helo you on windows :/

  1. You really make it seem so easy with your presentation
    but I find this matter to be really something that I think
    I would never understand. It seems too complicated and very broad
    for me. I’m looking forward for your next post, I will try to get the hang of it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s