Organizations of various size implement CRM to enhance their productivity and customer relationship. Making the best out of it for the users will increase in their productivity and that leads to an increase in revenue and profitability of the organization.
Sending out emails is the area where representatives spend a lot of time. Automating the email sending system where the reps intervention is not needed will help reps to focus on other important areas.
Well, while implementing such automated systems there are certain things that need to be taken care of to avoid bottlenecks. Sending an email blast to a large number of emails will slow down the instance and affect other functionalities. This situation can be overcome by first creating email drafts and then scheduling the same to be done at off peak times. This approach will also helps you to track the status of the email.
In this article, we are going to see how auto email drafts can be created and sent later.
Outbound email from SugarCRM
Consider an organization ABC which maintains sales force related tasks within a CRM solution. The requirement is they need an auto emailing system that sends a reminder for task approaching their due dates (let us say 3 days from now). Another follow up email for tasks where timelines are exceeded by 3 days.
SugarCRM comes with a feature of creating an email draft and send it at a later time. The above requirement can be achieved by creating three schedulers i.e. 2 schedulers are to draft email reminders and email warnings and 3rd one is to send the email drafts to assigned persons.
Steps to create Email Drafts
Below are the steps to create a custom scheduler that drafts emails reminders and warnings. You can find more about SugarCRM schedulers here.
- The first step is to create a label extension file. This is a display text for the scheduler job when creating from Admin->Scheduler. Below is the path for creating the file.
./custom/Extension/modules/Schedulers/Ext/Language/en_us.task_emails.php.
- Place the below code in the language file.
<?php $mod_strings[‘LBL_OVER_DUE_TASKS’] = 'Send Warnings for the overdue tasks'; $mod_strings[‘LBL_DUE_TASKS’] = 'Send Reminder for the due tasks';
- Now, define the custom jobs function in the below path
./custom/Extension/modules/Schedulers/Ext/ScheduledTasks/task_emails.php
- Place the below code in the scheduler file.
<?php array_push($job_strings, 'over_due_tasks'); array_push($job_strings, 'due_tasks'); function over_due_tasks() { //$array_tasks = write the logic to get task details(i.e. necessary details to create email)of last 3 days which are not closed email_draft($array_tasks); return true; } function due_tasks() { //$array_tasks = write the logic to get task details(i.e. necessary details to create email)of next 3 days which are not scheduled email_draft($array_tasks); return true; } /** * creates email drafts * @param array $array_tasks [name, sub, body_html, email, ...] */ function email_draft($array_tasks) { foreach($array_tasks as $task){ $bean = \BeanFactory::newBean('Emails'); //this state defines the email as draft $bean->state = \Email::STATE_DRAFT; $bean->name = '{Subject text}'’; $bean->description_html = '{html body}'; $bean->to_addrs_arr[] = [ 'email' => '{get assigned person email id}', 'display' => '{get assigned person name}' ]; $bean->parent_type = 'Tasks'; $bean->parent_id = $task['id']; $bean->save(); } }
- While creating the email draft in the above code “$bean->state = \Email::STATE_DRAFT” make sure the email state is assigned as a draft.
Steps to send Email Drafts
Below are the steps to create a custom scheduler that sends email drafts to the assigned user.
- The first step is to create a label extension file. Below is the path for creating the file.
./custom/Extension/modules/Schedulers/Ext/Language/en_us.send_draft_emails.php.
- Place the below code in the language file.
<?php $mod_strings['LBL_SEND_DRAFT_EMAILS'] = 'Send drafted emails';
- Now, define the custom jobs function in the below path
./custom/Extension/modules/Schedulers/Ext/ScheduledTasks/send_draft_emails.php
- Place the below code in the scheduler file.
<?php array_push($job_strings, 'send_draft_emails'); /** * sends email drafts */ function send_draft_emails() { //$draft_email_ids = retrive all the drafted email ids foreach($draft_email_ids as $email_id){ $email_bean = BeanFactory::retrieveBean("Emails", $email_id); $email_bean->type = "out"; $email_bean->state = Email::STATE_READY; if ($email_bean->send()) { $email_bean->status = 'sent'; $email_bean->state = Email::STATE_ARCHIVED; } else { $email_bean->status = 'send_error'; $email_bean->state = Email::STATE_DRAFT; } $email_bean->save(); } }
- Each and every step in the send_draft_emails() function is very important and should be in the same order. [NOTE: The save method should be triggered after setting the state and status of the email bean]
- Once the schedulers are created do a quick repair and rebuild which will enable the options while creating scheduler jobs in Studio->Scheduler
Steps to create Scheduler Jobs
- Navigate to Admin->Scheduler->Create Scheduler.
- Enter the details like name, the time interval and select the job form the jobs dropdown.
- Make sure ‘Send drafted emails’ job is scheduled at once per day and in the offshore time to avoid a bottleneck situation.
Once all the above steps are implemented, jobs will run at the specified time interval and send the email drafts without any human intervention.
Email drafting feature in SugarCRM will help you implement Auto-Emailing jobs and also you can track the status of an email whether it is sent or not to the assigned person.
Evaluating SugarCRM for your business – We can help
Reach out to us so that we can assess and plan a road-map for your CRM implementation. Let’s build a system, which you will use for years to come.