Secondary email address of user

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxniebieski
    Junior Member
    • Jul 2024
    • 9

    Secondary email address of user

    How to use workflow to send email to secondary email address. There is no such option on the list, maybe there is a possibility to create a relationship with user entity?
    Generally I would like to send notifications not only to primary email addresses of users.

    Thanks in advance for help
  • yuri
    Member
    • Mar 2014
    • 8667

    #2
    You can use a formula variable as a placeholder in the email address field. You will need to obtain the email address with formula script and write it to some variable in the action above.

    Click image for larger version  Name:	image.png Views:	0 Size:	22.2 KB ID:	115235
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • maxniebieski
      Junior Member
      • Jul 2024
      • 9

      #3
      Thanks for the quick reply.

      I was thinking about it but if I want to send to the first (primary) and second user email at the same time it won't work I guess

      Comment

      • yuri
        Member
        • Mar 2014
        • 8667

        #4
        You can specify multiple email addresses separating them with a semicolon.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • maxniebieski
          Junior Member
          • Jul 2024
          • 9

          #5
          Maybe I'll write in detail.
          I want to send an email after creating a record to the user who created it to both of his addresses.
          I created an additional field in the user entity cCAdditionalEmail (store the second email address there), and in the workflow action of the type send email in cc I have a variable {$$emailRecipient) which I'm trying to get with a formula run in the action
          $emailRecipient = ifThen(
          string\length(entity\attribute('createdBy.cCAdditi onalEmail')) > 0,
          entity\attribute('createdBy.cCAdditionalEmail'),
          entity\attribute('createdBy.emailAddress')
          );

          Comment

          • lazovic
            Super Moderator
            • Jan 2022
            • 879

            #6
            Hi maxniebieski,

            With the following formula script, you can collect all the email addresses that are set in the default Email field, separated by a semicolon:
            Code:
            $emailAddressesCount = array\length(emailAddressData);
            
            $emailAddressData = json\encode(emailAddressData);
            
            $i = 0;
            
            while ($i < $emailAddressesCount) {
                
                $emailAddress = json\retrieve($emailAddressData, string\concatenate($i, '.emailAddress'));
                
                $emailAddressesArray = array\push($emailAddressesArray, $emailAddress);
                
                $i = $i + 1;
            }
            
            $emailAddresses = array\join($emailAddressesArray, ';');
            So, you will get approximately the following result, which will be stored in the $emailAddresses variable:
            Code:
            1@mail.com;2@mail.com;3@mail.com

            Comment

            • maxniebieski
              Junior Member
              • Jul 2024
              • 9

              #7
              Hi lazovic

              Thanks a lot for help, I'll try it

              Comment

              • maxniebieski
                Junior Member
                • Jul 2024
                • 9

                #8
                Unfortunately, this does not solve my problem - if I add a formula in the workflow, it does not know from whom to get the email addresses.
                The best solution would be that when a user has 2 or 3 or n email addresses, notifications are sent to all or to the ones I select.
                What is the purpose of being able to enter multiple email addresses for a user if it is not possible to use it or I do not know what the intention was.
                Maybe it is possible to set more than 1 email address as the main one?

                Comment

                • lazovic
                  Super Moderator
                  • Jan 2022
                  • 879

                  #9
                  maxniebieski,

                  You can easily extend the formula script to get all the email addresses of the user who created the record, as follows:
                  Code:
                  $emailAddressesCount = array\length(createdBy.emailAddressData);
                  
                  $emailAddressData = json\encode(createdBy.emailAddressData);
                  
                  $i = 0;
                  
                  while ($i < $emailAddressesCount) {
                      
                      $emailAddress = json\retrieve($emailAddressData, string\concatenate($i, '.emailAddress'));
                      
                      $emailAddressesArray = array\push($emailAddressesArray, $emailAddress);
                      
                      $i = $i + 1;
                  }
                  
                  $emailAddresses = array\join($emailAddressesArray, ';');
                  
                  output\printLine($emailAddresses);

                  Comment

                  • maxniebieski
                    Junior Member
                    • Jul 2024
                    • 9

                    #10
                    lazovic

                    it works perfect !! thank you for help !.

                    its open me a new opportunity

                    Comment

                    Working...