Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

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

Solved Go to solution

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

New Contributor

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

Accepted Solutions

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

Super 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.

2 REPLIES 2

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

Super 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.

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

New Contributor

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

Don't have an account?
Coming from Hortonworks? Activate your account here