BPM: Send E-Mail from another user

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lucakuehne
    Senior Member
    • Feb 2016
    • 195

    BPM: Send E-Mail from another user

    Hi

    I've created a flowchart for oppertunities, in which there is a script which sends emails:
    Code:
    while($outerPosition < array\length($oppertunityContactIds),
      $emailAdresse = record\attribute('Contact', array\at($oppertunityContactIds, $outerPosition), 'emailAddress');
      $emailId = record\create(
        'Email',
        'to', $emailAdresse,
        'status', 'Draft',
        'parentId', entity\attribute('id'),
        'parentType', 'Opportunity'
      );
      ext\email\send($emailId);
    );
    By default the email gets sent using the system-account, but I want to send it as the user which is assigned to the opportunity.
    I already tried it by adding " 'from', assignedUser.emailAddress, ", but then the email does not get send at all.

    How can I send the email as a different user than System?
  • lucakuehne
    Senior Member
    • Feb 2016
    • 195

    #2
    Happy New Year to everybody!

    I just wanted to push this thread up, as I didn't get a response for 5 days.

    And I wanted to add the following question: Is is even possible to send as another user than System?
    Last edited by lucakuehne; 01-04-2021, 10:10 AM.

    Comment

    • item
      Active Community Member
      • Mar 2017
      • 1499

      #3
      Hello,

      there exist : if (!$email->get('from'))

      so you can put 'from' param.
      now just find de correct way for get emailAddress :

      user.emailAddress or ..
      maybe it's assignedUserId so find it with formula.

      record\attribute('User', assignedUserId, 'emailAddress')

      I think it's something so


      If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

      Comment

      • lucakuehne
        Senior Member
        • Feb 2016
        • 195

        #4
        Hi item

        I don't know if I correctly understood your reply.

        But the problem is not getting the correct email-address. Even if I try to send the email with a hardcoded email-address like this it doesn't work:
        Code:
        $emailId = record\create(
          'Email',
          'from', 'ur***.ma***@so***.**',
          'to', 'lu***.ku***@so***.**',
          'body', 'TEST',
          'status', 'Draft'
        );
        ext\email\send($emailId);

        But if I remove the "from", the email gets sent:
        Code:
        $emailId = record\create(
          'Email',
          'to', 'lu***.ku***@so***.**',
          'body', 'TEST',
          'status', 'Draft'
        );
        ext\email\send($emailId);
        But I don't understand why, to be honest.
        Last edited by lucakuehne; 01-04-2021, 01:36 PM.

        Comment

        • lucakuehne
          Senior Member
          • Feb 2016
          • 195

          #5
          I tried it again and again and I'm starting to think it might be a bug.
          I did it exactly as in the docs.

          Could somebody from the team doublecheck this?

          Comment

          • Maximus
            Senior Member
            • Nov 2018
            • 2731

            #6
            Hi,
            please read this manual carefully https://docs.espocrm.com/administrat.../#extemailsend.

            If from address is not set in the email, then system email address will be used. If there's match between from address and the address of some group email account, then SMTP setting of the group email account will be used.

            Comment

            • item
              Active Community Member
              • Mar 2017
              • 1499

              #7
              Hello,
              i think :
              look smtp setting in admin section..
              look user emailAccount in setting of user. (smtp/login/password)
              look log file, what's error ?
              in formula : $service->sendEntity($email);

              in application/Espo/Services/Email.php line 156 ..

              he search for user.. and try to get smtp/password for the user .. but in formula, there are no setting for user.

              I think, just rewrite new formula with :
              in formula find $user

              $service->sendEntity($email, $user);

              I think that will do the trick






              If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

              Comment

              • lucakuehne
                Senior Member
                • Feb 2016
                • 195

                #8
                Hi Maximus

                Thank's for your reply.

                I have read this manual already a few times, but my case is not covered in there.
                The address which I specified in the from-address, is the address of a personal email account.

                Comment

                • lucakuehne
                  Senior Member
                  • Feb 2016
                  • 195

                  #9
                  Originally posted by item
                  he search for user.. and try to get smtp/password for the user .. but in formula, there are no setting for user.
                  ...
                  $service->sendEntity($email, $user);

                  I think that will do the trick
                  I'm not sure if I got you right, but in that case I should be able to write a formular expression like this:
                  Code:
                  ext\email\send($emailId,$userId);
                  Then he should pick the SMTP-credentials from the user and send the email with those credentials, correct?


                  look log file, what's error ?
                  Code:
                  [2021-01-05 13:41:05] Espo.ERROR: Formula function: ext\email\send, Error while sending. Message: Email sending: No SMTP params found for ur***.ma***@so***.**.. [] []
                  But how can I define which SMTP credentials I want to choose... I already tried it using ext\email\send($emailId,$userId);, but this didn't work
                  Last edited by lucakuehne; 01-05-2021, 01:47 PM.

                  Comment

                  • item
                    Active Community Member
                    • Mar 2017
                    • 1499

                    #10
                    Hello,
                    yes ... sendEntity have two param, email and user. but formula don't have "user". So you need to create your own formula :


                    but maybe another solution after more look :

                    try this : assign user in this formula "record\create" ! Maybe that will do the trick !


                    $emailId = record\create( 'Email', 'to', $emailAdresse, 'status', 'Draft', 'parentId', entity\attribute('id'), 'parentType', 'Opportunity' );
                    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

                    Comment

                    • lucakuehne
                      Senior Member
                      • Feb 2016
                      • 195

                      #11
                      So sad there is no native way to do that....

                      I managed to write my own formula function using your help and the email is now getting sent as the defined user: Custom function -> SendFromUserType.zip
                      But the problem is, that the email now is getting sent two times. Both with the right "from" address, but in one the user based placeholders are based on the correct user and in the other one the placeholders are based on "System".

                      Do you got an idea why?
                      Attached Files
                      Last edited by lucakuehne; 01-05-2021, 06:47 PM.

                      Comment

                    Working...