Announcement

Collapse
No announcement yet.

Bug in formula which sends emails

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bug in formula which sends emails

    Hello Guys,
    i want to send email with attachment. Everything is okay when i'm generating first PDF based on PDF Template and then adding attachment to formula, but there is an issue which i managed to reproduce on official demo, when i want to send email with attachment which is already in EspoCRM.

    How to reproduce:
    1. Log in to official demo
    2. Create new Flowchart with start and formula like on a screenshot bellow
    3. Enter formula like below
    4. Go to record and trigger process
    It'll generate email without attachment. Even more interesting is fact that in data of generated email there is param hasAttachment set to TRUE.
    PHP Code:
    $attachmentId '5a86df2dc332967d6';
    $emailId record\create('Email',
    'to''test@domain.com',
    'attachmentsIds', list('$attachmentId')
    );

    ext\email\send($emailId); 

  • #2
    Here you have also screenshot from email. As you can see there is attachment icon, but no attachment.
    Attached Files

    Comment


    • #3
      Hello Emil,
      it’s list($attachmenId)

      and don’t forget : parentId, parentType maybe

      when on computer, I post full now I am on iPad

      regards

      Comment


      • #4
        Oh, you're right! I'll check again.

        Comment


        • #5
          Still doesn't work
          Attached Files

          Comment


          • #6
            Here a working in 6.1.10 :
            $attachmentName = string\concatenate($factureName, '.pdf');
            $attachmentId = ext\pdf\generate('Facture', $factureId, $factureTemplateId, $attachmentName);
            $emailId = record\create('Email',
            'to', $contactEmailAddress,
            'attachmentsIds', list($attachmentId),
            'parentId', $contactId,
            'parentType', 'Contact',
            'teamsIds', list('5c3d1e8c46564a468', '5c3d03880e28c1b49')
            );
            ext\email\applyTemplate($emailId, $emailTemplateId);
            ext\email\send($emailId);

            As you see, i use a emailTemplate.. i have just see :
            subject is required field
            https://docs.espocrm.com/administrat.../#extemailsend

            You can see in admin section => attachment if your attachment is created and in email if your mail is send (click all folder)

            Comment


            • #7
              This is not a bug. It's not documented that this supposed to work. Please create such issues in the Developer Help section,

              Comment


              • #8
                yuri you mentioned in documentation that ext/pdf/generate is simple id of attachment, that's why i assumed that it should also work with already existing attachments.

                Comment


                • #9
                  One attachment record can be only in one email record. It's how it was designed. You can copy an attachment (with the sourceId field set with an ID of the original) or apply an email template with the attachment.

                  See https://github.com/espocrm/espocrm/issues/2050

                  Comment


                  • #10
                    yuri in my opinion, if system don't want to assign already existing attachment, it shouldn't also add param to email hasAttachment: true.
                    I've managed to create email with already existing attachment thanks to this formula:

                    PHP Code:
                    $fileId '5a86df2dc332967d6';

                    $attachmentId record\create('Attachment',
                    'role''Attachment',
                    'type'record\attribute('Attachment'$fileId'type'),
                    'size'record\attribute('Attachment'$fileId'size'),
                    'global'record\attribute('Attachment'$fileId'global'),
                    'name'record\attribute('Attachment'$fileId'name'),
                    'sourceId'$fileId,
                    'storage'record\attribute('Attachment'$fileId'storage')
                    );

                    $emailId record\create('Email',
                    'to''test@domain.com',
                    'attachmentsIds', list($attachmentId)
                    );

                    ext\email\send($emailId); 

                    Comment


                    • yuri
                      yuri commented
                      Editing a comment
                      This is an insignificant issue. Not considered as a bug. It never happens if used properly. "Fixing" this small thing will complicate the system. Does not worth the benefit. One can pass "hasAttachment": true to the entity via formula, and the result will be the same, Formula does not give 100% foolproof API, and it was never a goal.
                      Last edited by yuri; 05-01-2022, 04:02 PM.
                  Working...
                  X