Email not auto importing

Hi emails are working with the CRM, in the email field i can see all my in box, manually import emails in to modules.

within the cases module if i create or update the case it will auto send out a message. but if someone replies to the message, it will not auto add the email to the case.

These are my inbound email settings:

Import Emails Automatically: Yes
Create Case from Email: No
Auto-Reply Template: None
No Auto-Reply to this Domain: none
Leave Messages On Server: Yes

Any help would be greatly appreciated.

Verify inbound_email_case_subject_macro varialbe in your config.php or config_override.php exit and what is the value of it.
It should be something like,

'inbound_email_case_subject_macro' => '[CASE:%1]',

to identify the case no and update it.

if it doesn’t exist you need to save from listView of Inbound Email then it will automatically update above variable.

Hi, Thanks for the reply,

I can confirm that ‘inbound_email_case_subject_macro’ => ‘[CASE:%1]’, is in my config.php file.

Any other Suggestions?

My bad,

Why it is
Create Case from Email: No ?

It should be Yes, no?

“Create Case from Email:” - is this create a case from each email received that is not linked to a case? If so, we do not want this.

We want emails with the case reference number in the subject (added by the system) to be automatically added to the case. I think this option is “Import Emails Automatically” ?

One more thing.
Can you verify if you have below logic hook entry at custom/modules/Emails/logic_hooks.php

$hook_array['after_save'][] = Array(10, 'Save email case updates', 'modules/AOP_Case_Updates/CaseUpdatesHook.php','CaseUpdatesHook', 'saveEmailUpdate'); 

Hi regarding the “Create Case from Email” this has made no difference.

The custom/modules/Emails/logic_hooks.php file contains:


// Do not store anything in this file that is not part of the array or the hook version.  This file will
// be automatically rebuilt in the future.
 $hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(10, 'Save email case updates', 'modules/AOP_Case_Updates/CaseUpdatesHook.php','CaseUpdatesHook', 'saveEmailUpdate');

Thanks

Make sure you have Enabled AOP and have made all the settings required in Admin -> AOP Settings

@peted what is your version of SuiteCRM?

Is this a Group Email account?

Hi

Please find attached an image of the EOP Setting. I have added the the parameters with red arrows as these were missing, but still not working.

Thanks

HI pgr,

it is a group email. and Version 7.10.7

Thanks

Please see attached email set-up.

Can you make the log statements to fatal instead of warn ?
Check the function saveEmailUpdate($email) in modules/AOP_Case_Updates/CaseUpdatesHook.php

make the $GLOBALS[‘log’]->warn() statements to $GLOBALS[‘log’]->fatal();
and observe the suitecrm.log when you think a case update happens.

Make sure the scheduler “Check Inbound Mailboxes” is Active and running and also check if cronjob is executing.

Thanks for the next steps, Sorry i am quite new to SuiteCRM, Can you offer some advice on how to do what you are asking?

Thanks.

Hi,

in modules/AOP_Case_Updates/CaseUpdatesHook.php

there is: public function saveEmailUpdate($email)

scheduler “Check Inbound Mailboxes” is Active and the cront tab must be running as the work flows are running. also when running this command:

sudo crontab -e -u www-data
the contents is:

          • cd /var/www/html; php -f cron.php > /dev/null 2>&1 
            

However every job log for all schedule tasks are empty.

I am just unsure who to do:

Cheers

I think it it a crontab issue,

When i run the command:

sudo -u www-data php -f cron.php

All the emails appeared in the correct cases.

  1. Have you set up the cronjob?
  2. Scheduler is Active?

Keep the backup of the file modules/AOP_Case_Updates/CaseUpdatesHook.php
replace the function with below code.
4)
Once done make a case update via email and monitor the suitecrm.log
I have made the log statement to fatal so that you will see if it comes in the function, if yes where does it go.


public function saveEmailUpdate($email)
    {
        $GLOBALS['log']->fatal("comes in saveEmailUpdate");
        if ($email->intent !== 'createcase' || $email->parent_type !== 'Cases') {
            $GLOBALS['log']->fatal('CaseUpdatesHook: saveEmailUpdate: Not a create case or wrong parent type');

            return;
        }
        if (!isAOPEnabled()) {
            $GLOBALS['log']->fatal('AOP is Disabled');
            return;
        }
        if (!$email->parent_id) {
            $GLOBALS['log']->fatal('CaseUpdatesHook: saveEmailUpdate No parent id');

            return;
        }

        if ($email->cases) {
            $GLOBALS['log']->fatal('CaseUpdatesHook: saveEmailUpdate cases already set');

            return;
        }

        if ($email->fetched_row['parent_id']) {
            //Will have been processed already
            $GLOBALS['log']->fatal("comes in parent_id. Will have been processed already");
            return;
        }

        $ea = new SugarEmailAddress();
        $beans = $ea->getBeansByEmailAddress($email->from_addr);
        $contact_id = null;
        foreach ($beans as $emailBean) {
            if ($emailBean->module_name === 'Contacts' && !empty($emailBean->id)) {
                $contact_id = $emailBean->id;
                $this->linkAccountAndCase($email->parent_id, $emailBean->account_id);
            }
        }
        $caseUpdate = new AOP_Case_Updates();
        $caseUpdate->name = $email->name;
        $caseUpdate->contact_id = $contact_id;
        $updateText = $this->unquoteEmail($email->description_html ? $email->description_html : $email->description);
        $caseUpdate->description = $updateText;
        $caseUpdate->internal = false;
        $caseUpdate->case_id = $email->parent_id;
        $caseUpdate->save();
$GLOBALS['log']->fatal("Case update Done.");        
        $notes = $email->get_linked_beans('notes', 'Notes');
        foreach ($notes as $note) {
            //Link notes to case update also
            $newNote = BeanFactory::newBean('Notes');
            $newNote->name = $note->name;
            $newNote->file_mime_type = $note->file_mime_type;
            $newNote->filename = $note->filename;
            $newNote->parent_type = 'AOP_Case_Updates';
            $newNote->parent_id = $caseUpdate->id;
            $newNote->save();
            $srcFile = "upload://{$note->id}";
            $destFile = "upload://{$newNote->id}";
            copy($srcFile, $destFile);
        }

        $this->updateCaseStatus($caseUpdate->case_id);
        $GLOBALS['log']->fatal("Ends: saveEmailUpdate");
    }

Correct so can you confirm if crontab -e shows you the crm cron.php’s entry?

crontab -e shows a crontab file with no entires.

sudo crontab -e -u www-data does have the entry:

          • cd /var/www/html; php -f cron.php > /dev/null 2>&1

OK, So i have it working now. I have created a crontab job under root and added the following command:

          • cd /var/www/html; sudo -u www-data php -f cron.php > /dev/null 2>&1
            

So for some reason cron job is not working for www-data.

Is there any issues on my work-around?