0

I am trying to add a Logic Hook for Emails synced from IMAP Mail server. In the end i want trigger a hook when a new mail gets synced and check the senders mail if its saved in one of the accounts.

The problem is that the Synced Mails dont get saved (at least not in InboundMail or Emails module) so the after/before_save does not trigger.

Here is my hook from logic_hooks.php:

$hook_array['after_save'][] = Array(1, 'Create Lead', 'custom/modules/InboundEmail/LeadLogicHook.php', 'LeadLogicHook', 'handleLead');

It does not work in InboundEmail and Email Module.

And the LeadLogicHook:

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class LeadLogicHook 
{
    function handleLead($bean, $event, $arguments) 
    {
        _ppl("Test");
    }
}

Is this even possible with logic hooks?

EDIT: Added some Code

Velrest
  • 300
  • 1
  • 3
  • 18

3 Answers3

1

I think it's possible, if after/before_save not triggering then try some similar logic hooks. The following are some logic hooks that I think could help.

  • before_retrieve
  • after_retrieve
  • before_restore
  • after_restore
  • server_roundtrip
  • after_session_start
  • after_entry_point

Comment if you want more details, like how to use logic hooks e.t.c.

Star
  • 3,222
  • 5
  • 32
  • 48
Ravi Ranjan
  • 105
  • 1
  • 13
  • Sorry I was a little unspecific on when i want to trigger my action. I need to trigger my hook when a new mail is synced from the IMAP server. so I cant really use the hooks you suggested. – Velrest Sep 22 '17 at 11:26
1

What version of sugar are you using?

You can, for example, generate an after_save hook in the E-mail module instead of inboundEmail

Would be like this:

$hook_array ['after_save'] [] = Array (1,'Create Lead','custom/modules/Emails/LeadLogicHook.php','LeadLogicHook','handleLead');

Do this and see if the email fires! Another possibility would be to use the after_relationship_add, because usually, the email is associated with some lead, account, or contact. try to create a hook in the module that your email is associating with and generate the operation from there

one last possibility (I do not recommend this) is to create a trigger in your database for when the data enters the table, perform the check and take some action

Star
  • 3,222
  • 5
  • 32
  • 48
Newkstron
  • 25
  • 1
  • 5
  • I already tried this one. The problem is that emails synced form a imap server do not get stored like other beans, the only get cached. I already tried the after_relationship_add hook on the accounts and the Emailaddress module but both didnt fire. – Velrest Sep 25 '17 at 07:20
  • And Version is: 7.7.6 – Velrest Sep 25 '17 at 07:49
1

No need for logic hook or any other custom code. Sugar/SuiteCRM use a scheduler job to fetch email from IMAP server. You can check scheduler job function (function::pollMonitoredInboxes) which fetch emails. That contain code which is used for email fetching. track back code and you will find everything you want.

Star
  • 3,222
  • 5
  • 32
  • 48