Case AOP emails to work with non contacts

I’m looking to make cases, case updates, work with non contacts in our system. Ticketing system for all emails would be an excellent way to manage communications in general. I can have an overall company email that gets responded to regardless. Without having to use an outside ticketing system. Currently, the cases and aop_cases modules do a fine job of this but, they do not work with users that are not contacts in the system.

So, I am looking at code, if anyone has suggestions, it would be great to collab with me.

ugh, what a pain, a great help is understanding how email are created when a case is created, updated, and closed.

All that is present in the logic_hooks.php in /custom/modules/Cases/logic_hooks.php

I’m trying to think of a good way to pull the initial email or emails in the thread that are not the assigned_user or system emails to send ticket updates to.

For example, I could store the email of who created it in a field, but that would not be good for threads with multiple people. Also I’m getting used to beans again as it has been a few months to understand the structure.

I simply want to insert if’s all over the place. So if contact is not present then send to emails in the thread that are not users or system admins. When it comes to updates, ticket creation and ticket closing.

I’m simply poking around trying to see hot to get this working. I think i might be able to with some simple code changes.

So far I am working backwards. So right now I have been able to get the email close to send. First I edited AOPInboundEmail.php

Particularly the handleCreateCase function.

First I wanted to change the priority to low for every created case. Not all emails are high priority, and we can then change the priority to high or medium dependent on the case.


$c->assigned_user_id = $userId;
            $c->name = $email->name;
            $c->status = 'New';
            $c->priority = 'P3';//HERE I CHANGED THE PRIORITY FROM P1 to P3

Then in studio I created a custom field called email_c to store the incoming email that created the case. Later I should expand this to find a method to save all emails in the thread. So all emails in the thread can be updated. Like if we included a manager etc.

So after the above code in the function i added


if(!empty($email->reply_to_email)) {
                $contactAddr = $email->reply_to_email;
            } else {
                $contactAddr = $email->from_addr;
            }
			
			//ADDING STORING EMAIL FROM WHO CREATED THE CASE, THE ORIGIN EMAIL!
			//MAYBE THIS WILL WORK TOWARD GETTING CASES TO WORK WITH ALL EMAILS
			$c->email_c = $contactAddr;

Then I had to look in CaseUpdatesHook.php located /modules/AOP_Case_Updates/

Changed the following code inside sendClosureEmail function


        $contact = $bean->get_linked_beans("contacts","Contact");
        if($contact){
            $contact = $contact[0];
        }else{
            return false;
        }

        $emailSettings = getPortalEmailSettings();

        $text = $this->populateTemplate($email_template, $bean, $contact);
        $mailer->Subject = $text['subject'];
        $mailer->Body = $text['body'];
        $mailer->IsHTML(true);
        $mailer->AltBody = $text['body_alt'];
        $mailer->From     = $emailSettings['from_address'];
        $mailer->FromName = $emailSettings['from_name'];

        $email = $contact->emailAddress->getPrimaryAddress($contact);

To this code


$contact = $bean->get_linked_beans("contacts","Contact");
        if($contact){
            $contact = $contact[0];
			$emailSettings = getPortalEmailSettings();

			$text = $this->populateTemplate($email_template, $bean, $contact);
			$mailer->Subject = $text['subject'];
			$mailer->Body = $text['body'];
			$mailer->IsHTML(true);
			$mailer->AltBody = $text['body_alt'];
			$mailer->From     = $emailSettings['from_address'];
			$mailer->FromName = $emailSettings['from_name'];

			$email = $contact->emailAddress->getPrimaryAddress($contact);
        }else{
			$emailSettings = getPortalEmailSettings();

			$text = $this->populateTemplateNoContact($email_template, $bean);
			$mailer->Subject = $text['subject'];
			$mailer->Body = $text['body'];
			$mailer->IsHTML(true);
			$mailer->AltBody = $text['body_alt'];
			$mailer->From     = $emailSettings['from_address'];
			$mailer->FromName = $emailSettings['from_name'];

			$email = $bean->email_c;
			
            //return false;
        }

I also created a copy of the populateTemplate function to one that does not include contacts.


private function populateTemplateNoContact(EmailTemplate $template, aCase $bean){
        global $app_strings, $sugar_config;
        //Order of beans seems to matter here so we place contact first.
        $beans = array(
            //"Contacts" => $contact->id,
            "Cases" => $bean->id,
            "Users" => $bean->assigned_user_id
        );
        $ret = array();
        $ret['subject'] = from_html(aop_parse_template($template->subject,$beans));
        $ret['body'] = from_html($app_strings['LBL_AOP_EMAIL_REPLY_DELIMITER'].aop_parse_template(str_replace("\$sugarurl",$sugar_config['site_url'],$template->body_html),$beans));
        $ret['body_alt'] = strip_tags(from_html(aop_parse_template(str_replace("\$sugarurl",$sugar_config['site_url'],$template->body),$beans)));
        return $ret;
    }

So far this allows the case close email to be sent without a contact

Ah I give up, i simply don thave the time to rewrite how cases handle inbound email.

Seriously though, I need to figure out where to submit featue request, this would be a great way to have osticket type functionality. For now, i will have to teach people how to handle cases for non contacts.

did you get any update about it?
I’m having the same issue and I’ll try to apply your workaround.