Created on 05-16-2018 11:10 PM - edited 08-18-2019 12:05 AM
I have a business case where the user wants to send a personalized email to a group of recipients and attach a PDF to the email.
I already had a working flow for him that took the list of emails and recipient names in a csv file, parsed those out row-by-row, converted to json, evaluated the json to assign values to attributes, and then send the email (see image), but I'm having trouble with the attachment part since the PDF isn't part of the flowfile.
Is there a way to pull the PDF into NiFi and assign the attributes needed from perhaps a map file or something? or replace the flowfile with the PDF and maintain the attributes? Once the attributes are assigned, I don't need the .csv data anymore.
Any help would be appreciated!
Created on 05-17-2018 12:59 AM - edited 08-18-2019 12:05 AM
If the PDF file path don't change then you can use UpdateAttribute processor after EvaluateJsonPath
add new properties in update attribute processor.
Then use Fetch File processor
to fetch pdf file for every receipt then use PutEmail processor to send the attached pdf file and include all the attributes.
Flow:
--other processors--1.EvaluateJsonPath Processor //extract values as attributes2.UpdateAttribute Processor //add directory,filename attributes to the flowfiles3.FetchFile Processor //to fetch the PDF file now we are overwriting the contents of flowfile,attributes will be same there4.PutEmail
By using this way we are fetching the pdf file for every email receipt.
(or)
Method2:
Keep your pdf file into Distribute Cache map server using PutDistributedMapCache processor with some id and configure/enable DistributedMapCacheClientService,DistributedMapCacheServer controller services.
then use the same DistributedMapCacheClientService Controller server in FetchDistributedMapCache processor with the same id that specified while keeping the pdf file in PutDistributeMapCache to fetch the file from the Distributecache server.
By following this way we are not fetching the file from local directory instead we are loading into NiFi and pulling from the DistributedCache.
Flow1:
Put pdf file into DistributedMapCache:
1.GetFile //get the file from directory (or) you can use Listfile/FetchFile processors also 2.UpdateAttribute //add the Cache Entry Identifier key and value 3.PutDistribuedMapCache //put the pdf file into DistributedMapCache
Flow2:
Actual Flow to send mail with pdf file attached:
--other processors--1.EvaluateJsonPath 2.UpdateAttribute //add the Cache Entry Identifier key and value3.FetchDistributedCacheMap //to fetch the pdf file4.PutEmail
-
If the Answer addressed your question, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.
Created on 05-17-2018 12:59 AM - edited 08-18-2019 12:05 AM
If the PDF file path don't change then you can use UpdateAttribute processor after EvaluateJsonPath
add new properties in update attribute processor.
Then use Fetch File processor
to fetch pdf file for every receipt then use PutEmail processor to send the attached pdf file and include all the attributes.
Flow:
--other processors--1.EvaluateJsonPath Processor //extract values as attributes2.UpdateAttribute Processor //add directory,filename attributes to the flowfiles3.FetchFile Processor //to fetch the PDF file now we are overwriting the contents of flowfile,attributes will be same there4.PutEmail
By using this way we are fetching the pdf file for every email receipt.
(or)
Method2:
Keep your pdf file into Distribute Cache map server using PutDistributedMapCache processor with some id and configure/enable DistributedMapCacheClientService,DistributedMapCacheServer controller services.
then use the same DistributedMapCacheClientService Controller server in FetchDistributedMapCache processor with the same id that specified while keeping the pdf file in PutDistributeMapCache to fetch the file from the Distributecache server.
By following this way we are not fetching the file from local directory instead we are loading into NiFi and pulling from the DistributedCache.
Flow1:
Put pdf file into DistributedMapCache:
1.GetFile //get the file from directory (or) you can use Listfile/FetchFile processors also 2.UpdateAttribute //add the Cache Entry Identifier key and value 3.PutDistribuedMapCache //put the pdf file into DistributedMapCache
Flow2:
Actual Flow to send mail with pdf file attached:
--other processors--1.EvaluateJsonPath 2.UpdateAttribute //add the Cache Entry Identifier key and value3.FetchDistributedCacheMap //to fetch the pdf file4.PutEmail
-
If the Answer addressed your question, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.
Created 05-17-2018 05:03 PM
Thank you! I knew there had to be simple answer - I used the first method and it worked great! Thanks again for your help.
Created 02-11-2021 10:00 PM
@Shu_ashu How to configure the flow if EvaluateJsonPath Processor flow have recipient mail id and FetchFile has the file path. I have configured as below but two mails are getting triggered. Could you help to modify the flow so that only one mail with attachment will trigger ?