1 2 Previous Next 15 Replies Latest reply on Oct 25, 2016 3:03 PM by dougnewnham

    Emailing PDF Attachments from FM Server

    dougnewnham

      Hi,

       

      I've spent quite a few days looking for solutions and figured I should ask the community!

       

      I have a customer that I'm developing for that needs an emailing solution.  Ideally I want to have a server script to email out a batch of purchase orders from PDFs sitting in containers, rather than have them email them manually one by one.  While it can be done one by one on their one machine with FM Pro they also run quite a lot of Webdirect clients that cannot create or email pdfs.  The ultimate answer for me is to send a batch of emails from the server.  Of course I've discovered that FM Server cannot export the contents of a container.  This then lead to me experimenting with external storage of container fields but it appears that FM Server cannot access those folders via a script.  I've tried attaching PDF's from the default folder location for the container contents.  I get an email but no attachment.  I'm assuming this is permissions/security related? I've also read that accessing these storage locations for container fields is a bad idea - given that the PDF's are temporary and are over-written each day I am not really that concerned about accessing them unless someone can tell me why it's a bad idea.  So....do I pursue addressing the permissions (or is that not possible) or should I be looking at other avenues? Locating the files in a location accessible by FM Server?

       

      My only other option I've heard of is to use a robot machine (FM Pro) on the server to do this task for me using the export field contents and email step but I haven't quite got my head around how to make it execute on demand.

       

      So my ultimate question is - how do I send a batch of emails from a Webdirect client with PDF attachments?

       

      Many thanks.

        • 1. Re: Emailing PDF Attachments from FM Server
          mikebeargie

          Mike Duncan has a cool technique where you can zip multiple containers into a single file:

          Extending Webdirect: Automatically Zip Container Fields - Soliant Consulting

           

          If you read up on the documentation for the send mail script step:

          Send Mail

           

          Two important notes from that:

          FileMaker WebDirect does not support the Attach File option. FileMaker WebDirect also does not support the Perform without dialog option when sending mail via an email client.

           

          FileMaker Server scheduled scripts support sending mail via SMTP. However, if you attach a file, that file needs to be in a folder that FileMaker Server is allowed to export to. For more information, see Get(DocumentsPath) function.

           

          What I normally do for user emails that need attachments from webdirect, is create a "queue" table in filemaker that has the email details (to,from,attachment container, subject, body). Then I run a server scheduled script that will process that queue, sending via SMTP.

           

          Back to that first link, you can modify that CWP so that it generates the zip file directly to your server's documents folder, and that way you will have the zip file accessible for attaching to the email. If you name it the same thing each time you can force it to overwrite the old file (as to not fill up your server documents folder with old attachments)

           

          Since you said you ideally want the server to run it anyways automatically, you can probably skip the WebDirect part all together and just perform all the actions you need on the server.

           

          So to recap:

          1) Generate zip file of container contents. You can use Insert From URL to trigger the PHP that generates the zip to execute.

          2) Send email using SMTP, attaching the generated zip file from the documents folder.

          2 of 2 people found this helpful
          • 2. Re: Emailing PDF Attachments from FM Server
            dougnewnham

            Hi,

             

            Thanks.  I'll take a look at it although I want this feature accessible to the FM Pro users as well as ipad users.  I'm not sure of the implications there as I'm only just starting with Webdirect and have no PHP experience.  Just to be a bit clearer - I want to send, as an example, 10 separate emails to 10 separate suppliers each with their own PDF from a container associated with their supplier record. ie. I need the server to loop through the selected suppliers and email the attachment.  As always, it's the FM server access to that container field that is my challenge.

            • 3. Re: Emailing PDF Attachments from FM Server
              Mike Duncan

              If you already have the PDFs in container fields, you can use the Base Elements plugin on the server (no plugin required for the end user) to export the container field using the "BE_ExportFieldContents" function.

               

              Export the PDF to the documents folder, then you can attach it to an email and send via SMTP.

               

              This would need to run on a script on the server, which you can kick off with a Perform Script on Server step. You might pass it a parameter with the ID of the record to find, export the PDF and send the email(s).

               

              Would that work better?

              Mike

              • 4. Re: Emailing PDF Attachments from FM Server
                dougnewnham

                I literally just found reference to the Base Elements plugin in these forums 40 minutes ago when I searched for 'export container contents server' !! Perfect.  Thankyou Mike!  I had investigated BE a few nights ago but didn't find their function wiki so couldn't confirm it would export containers.  My second look this morning revealed all.

                 

                Thanks again.  Off to make it work now

                • 5. Re: Emailing PDF Attachments from FM Server
                  macwombat

                  Thanks Mike - I was looking for a solution to this problem (sending PDF from server side script) a couple of weeks ago, but wasn't satisfied with the solutions I found at the time.  Base Elements plugin sounds like the ideal solution.  Chris

                  • 6. Re: Emailing PDF Attachments from FM Server
                    rtor451

                    I have this exact same issue where I'm trying to create and send pdf file via a server script utilizing an smtp server. 

                     

                    At first, I had the pdf being created on the Get (temporary path) but I've changed it to Get (document path). 

                     

                    It doesn't work either way.  I suspect it a permissions issue, right? 

                    • 7. Re: Emailing PDF Attachments from FM Server
                      mikebeargie

                      rtor451, that is NOT the same issue.

                       

                      This thread is discussing emailing the contents of a container field, something that is already generated.

                       

                      Save as PDF is not a supported script step for a filemaker server scheduled script.

                       

                      There are two ways around this:

                       

                      1) setup a "robot" filemaker pro machine that will generate a PDF to a container field on demand.

                       

                      2) setup a PHP script that will "insert from URL" a PDF file into a container field on demand.

                       

                      #2 is outlined well here:

                      https://www.dbservices.com/articles/how-to-create-a-pdf-from-filemaker-server/

                       

                      #1 can be seen here:

                      Printing PDFs in FileMaker WebDirect - SeedCode 

                       

                      And the documentation for "Save Records as PDF", stating that it's not compatible with server scheduled scripts, can be found here:

                      Save Records As PDF

                      • 8. Re: Emailing PDF Attachments from FM Server
                        rtor451

                        You are correct Mike.  this is not the same issue.  I never checked to see if the Save as PDF script step was compatible on the server.  That clears it up.  Thanks.

                        • 9. Re: Emailing PDF Attachments from FM Server
                          martinc

                          If I can get my server to attach what's in our container fields, that would be huge!

                          We use server side scripts for lots of reporting.  The big downfall is the lack of attachments.

                           

                          I tried adding this to one of our server reporting scripts that uses SMTP:

                          Screen Shot 2016-10-24 at 8.38.52 AM.png

                           

                          Our server has a "D" drive that holds that data.  Can I point one of the variables to "D", export the container there, and then attach it?

                          We are using fms14 and will be moving to 15 in the next couple of weeks

                           

                          Screen Shot 2016-10-24 at 8.36.55 AM.png

                          • 10. Re: Emailing PDF Attachments from FM Server
                            dougnewnham

                            Hi,

                             

                            It's pretty easy once you have the Base Elements Plug in (Free).

                             

                            Let me know if you want some help?

                            • 11. Re: Emailing PDF Attachments from FM Server
                              martinc

                              Thank you.  I like 'pretty easy'

                               

                              I loaded the Base Elements plug in on our server.

                              I'm solid on the FM sending email with SMTP on the server.  Using the BE functions is a challenge.  The support page is a bit beyond me.

                              I could certainly use some help with how to use BE to get an attachment into a SMTP email.

                               

                              Thanks

                              • 12. Re: Emailing PDF Attachments from FM Server
                                dougnewnham

                                I have re-read your post and the one stumbling block might be accessing the D:drive.  From memory I had to use the filemaker document path because the server cannot access other directories beyond this one.  In other applications I have worked around that by running a robot or slave FM Pro instance on the server so that it can access other drives (dropbox for example).  I also run a VB script (Windows machine) to delete the PDF's every night.

                                 

                                Email from server.PNG

                                • 13. Re: Emailing PDF Attachments from FM Server
                                  dougnewnham

                                  File path was truncated in the SS above.  I might be showing my ignorance but this was what worked on a Windows server...:

                                   

                                  "C:\Program Files\FileMaker\FileMaker Server\Data\Documents" & Char(92) & $filename

                                  • 14. Re: Emailing PDF Attachments from FM Server
                                    martinc

                                    I must be getting close....still no attachment

                                    Screen Shot 2016-10-25 at 7.58.49 AM.png

                                    1 2 Previous Next