Announcement

Collapse
No announcement yet.

Send multiple mails with PDFs attached

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

  • Send multiple mails with PDFs attached

    I am stuck with a problem and need some
    I have a custom entity "invoices" with a date field for sending out the next invoice and a due date field.
    Click image for larger version

Name:	image.png
Views:	91
Size:	77.3 KB
ID:	111769
    How is it possible to send out all invoices as PDF by email at once? Preferrably automated by a scheduler. I have the extensions Advanced Pack and Sales Pack.

    Many thanks for any help/hint

    Boris

  • #2
    Hi boris,

    To have invoices sent automatically, for example, at 10 AM on the day of the Payment Deadline, you should do the following:
    1. Create a report with a List type, an Invoice target type, and a filter: Payment Deadline field equals today:

      Click image for larger version

Name:	image.png
Views:	90
Size:	36.2 KB
ID:	111771
    2. Create a workflow with the following settings and actions:​

      Click image for larger version

Name:	Screenshot from 2024-10-27 12-41-46.png
Views:	59
Size:	62.0 KB
ID:	111772
    More about workflows with a Scheduled type you can find here: https://docs.espocrm.com/administrat...ows/#scheduled.

    More about Run Service Action you can find here: https://docs.espocrm.com/administrat...service-action.

    Comment


    • #3
      Hi lazovic,
      many thanks for your fast reply. The lists have pointed me in the right direction. I have now one problem left:
      Click image for larger version

Name:	image.png
Views:	58
Size:	42.9 KB
ID:	111776
      The Service Method dropdown is empty. I don't have anything to select here. Any ideas?

      Comment


      • #4
        Found out, that Send in Mail service method is only available for the entity invoice of the sales pack. Any chance to use the service method Send in Email in a custom entitiy for invoices?

        Comment


        • #5
          boris,

          In this case, you can use in this workflow the Execute Formula Script action with the ext\pdf\generate() function: https://docs.espocrm.com/administrat...extpdfgenerate. Something like this:
          Code:
          $invoiceId = workflow\targetEntity\attribute('id');
          
          $contactId = record\attribute('contactId');
          $emailAddress = record\attribute('Contact', $contactId, 'emailAddress');
          
          $attachmentId = ext\pdf\generate(
              'Invoice',
              $invoiceId,
              'pdf-template-id',
              'invoice.pdf'
          );
          
          $emailId = record\create('Email',
              'subject', 'Invoice PDF',
              'body', 'PDF is attached',
              'to', $emailAddress',
              'attachmentsIds', list($attachmentId)
          );
          
          ext\email\send($emailId);

          Comment


          • #6
            Hi lazovic,
            many thanks for your help. Just one small adjustment and it works like a charm:
            Code:
            $invoiceId = workflow\targetEntity\attribute('id');
            
            [B]$contactId = workflow\targetEntity\attribute('contactId');[/B]
            $emailAddress = record\attribute('Contact', $contactId, 'emailAddress');
            
            $attachmentId = ext\pdf\generate([INDENT]'Invoice',[/INDENT][INDENT]$invoiceId,
            'pdf-template-id',
            'invoice.pdf'[/INDENT]
             
            
            );
            
            $emailId = record\create('Email',[INDENT]'subject', 'Invoice PDF',
            'body', 'PDF is attached',
            'to', $emailAddress',
            'attachmentsIds', list($attachmentId)[/INDENT]
             
            
            );
            //this adds a template to the email:
            ext\email\applyTemplate($emailId, 'mail-template-id');
            
            ext\email\send($emailId);

            Comment

            Working...
            X