Validation on Reply Email Based on Case Origin + Multiple Outbound Email Accounts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IshitaRana
    Junior Member
    • Apr 2025
    • 14

    #1

    Validation on Reply Email Based on Case Origin + Multiple Outbound Email Accounts

    Hi,

    I’m trying to implement a validation check when replying to an email in EspoCRM, specifically for cases where the origin is set to a particular value.

    Here’s what I want to achieve:
    • If the parent entity of the email is a Case, and the cCaseOrigin field of that case is "Email-Unilever LD",
    • Then, I want to check the original "To" email address of the received (inbound) email.
    • If the inbound email was originally sent to final@example.com,
    • Then any replies to that email must be sent only from the email address abc@example.com.
    • If the user tries to send the reply from any other email account, I want to throw a validation error and prevent sending.

    I’ve written a before-send script to perform this check, and it seems to be picking up the case and the origin correctly. However, the validation is not working as expected — it still allows the email to be sent even when the "From" address does not match the required one.

    Additional Question:
    Is it possible to configure multiple outbound (sending) email addresses in EspoCRM, so that the user can reply from the same email address to which the original mail was received (especially for group email accounts)? If so, how can we manage this at the configuration?

    Thanks
  • lazovic
    Super Moderator
    • Jan 2022
    • 1124

    #2
    Hi IshitaRana,

    Can you please show your before-save script?

    Also, in EspoCRM you can set up several group accounts so that users can reply from them. You can find out more here: https://docs.espocrm.com/administrat...email-accounts.

    Comment

    • IshitaRana
      Junior Member
      • Apr 2025
      • 14

      #3
      this was my before-save script which I was using for testing purposes

      $mapping = object\create();
      object\set($mapping, 'final@example.com', 'abc@example.com');

      $sender = from;
      $replyFrom = to;

      $allowedFrom = $mapping[$sender] ?? null;

      if ($allowedFrom && $replyFrom != $allowedFrom) {
      recordService\throwBadRequest('Invalid "From" address for reply. Must reply from ' . $allowedFrom . '.');

      }​

      Comment

      • lazovic
        Super Moderator
        • Jan 2022
        • 1124

        #4
        IshitaRana,

        Can you please try to use the following formula script?
        Code:
        if (from == 'final@example.com') {
            $allowedFrom = 'abc@example.com'
        }
        
        if ($allowedFrom && to == $allowedFrom) {
            recordService\throwBadRequest(string\concatenate('Invalid "From" address for reply. Must reply from ', $allowedFrom, '.'))
        }

        Comment

        Working...