Code Blog

Displaying 1-2 of 2 results.
2016/02/15 SugarCRM

My aim was to create an automatic weekly status update email for SugarCRM CE. The CE version doesn't come with this functionality built-in but it's still quite easy to create a script in PHP and add a task in Windows "task scheduler" to send out the email at a specific time and interval.

This is how I did it. First you need to create the following three files in your SugarCRM CE installation folder (relative file paths given)

  1. custom/scripts/Weeklyemail.php
  2. custom/extensions/modules/schedulers/ext/ScheduledTasks/WeeklyEmailJob.php
  3. custom/extensions/modules/schedulers/ext/ScheduledTasks/language/en_us.WeeklyEmailJob.php

The Weeklyemail.php is the part which will actually create the content for the email to be sent out. I did this by running some database queries to generate the content from the CRM database (here you may put in whatever is relevatant for your business i.e. latest Opportunities, Sales statistics etc).

SugarCRM uses the PHPMailer library for sending emails. It is an objectoriented PHP library with support for SMTP. Here's a code example in SugarCRM for creating the mail object: 

$emailobj = new Email();
$defaults = $emailobj->getSystemDefaultEmail(); 
$mail = new SugarPHPMailer();

In this setup the outgoing email is sent via the local Exchange mail server (ip address in example above, port 587 with TLS). For this to work I had to enable "extension=php_ldap.dll" in php.ini. The username and password didn't carry over correctly so I set it again explicitly in the code.

I then set up a "Scheduled task" in Windows Server 2008 r2, see screenshots below. I create a new task in "Control panel -> Administrative Tools -> Task Scheduler". The process is quite similar for any Windows system.


Need to specify the directory for php.exe process to run in, it should be the root of the SugarCRM installation, otherwise it cannot find the cron.php script file.

2016/02/15 SugarCRM

In SugarCRM CE (the free Community Edition) there is no field for "Account name" for projects. However there already exists a relationship between Account and Project. But it is of type "Many-to-Many" and for my purpose "One-to-Many" Account/Project relationship would been more suitable.