Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

NiFi - is it possible to send an email with attachment to a variable list of recipients?

avatar
Explorer

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!

72882-screen-shot-2018-05-16-at-50131-pm.png

1 ACCEPTED SOLUTION

avatar
Master Guru
@K Henrie

If the PDF file path don't change then you can use UpdateAttribute processor after EvaluateJsonPath

add new properties in update attribute processor.

74456-updateattr.png

Then use Fetch File processor

74457-fetchfile.png

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.

View solution in original post

3 REPLIES 3

avatar
Master Guru
@K Henrie

If the PDF file path don't change then you can use UpdateAttribute processor after EvaluateJsonPath

add new properties in update attribute processor.

74456-updateattr.png

Then use Fetch File processor

74457-fetchfile.png

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.

avatar
Explorer

Thank you! I knew there had to be simple answer - I used the first method and it worked great! Thanks again for your help.

avatar
Explorer

@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 ? 

Aaki_08_0-1613109355117.png

 

Aaki_08_1-1613109616577.png