Support Questions

Find answers, ask questions, and share your expertise

Send attachment by email

Contributor

I need to send an attachment by email through Nifi, but I can't get the PDF file because there are several files from several people within the same directory, I have a BASE64_ENCODE field in the Oracle table that is the same as the generated PDF file.

 

How can I pass this information from this field through Nifi's PutEmail processor?

 

leandrolinof_0-1663176339122.png

 

 

leandrolinof_1-1663176362717.png

 

4 REPLIES 4

Master Guru

@leandrolinof 

I am having trouble understanding your query clearly.
The PutEmail processor ONLY supports talking the content of the source FlowFIle and adding it as the email message or adding it as an attachment to the email.  The putEmail processor is not involved at all with how the content was added or modified in the source FlowFile that comes from the upstream ExecuteSQL processor.

So what exactly are you trying to pass through the PutEmail processor?  The BASE64_ENCODE you are retrieving from Oracle?  You can write that to a FlowFile attribute.  The "Message" configuration property of the PutEmail processor, as well as many others, support using NiFi Expression Language (NEL).  That means you could read from the FlowFiles attributes anything you have placed there and insert it into the email message body.

If you can provide more detail it may be helpful.  It sounds like you want to send an email with aPDF file attachment, but sounds like you haven't even ingested the PDF into NiFi yet.

Thank you,
Matt

Contributor

@MattWho 

 

Sorry for the lack of clarity in the question.

In short, I need to send an attachment by PDF, but I can't select the file that I already have saved in PDF in a directory, because within that directory there are several PDFs from different buyers and the E-mail is sent one to each buyer by the PDF be different for each one.

 

The PDF is generated at a different time within my ERP system.

 

Is there a way for Nifi to understand that the Flow of that buyer that is coming is from a certain PDF within the directory by some identification? I do this by which Nifi processor?

To bring the buyer I execute a QUERY in Oracle by the ExecuteSQL processor returning the buyer's ID.

 

A second attempt to send the attachment would be, in this QUERY in ExecuteSQL I can bring together a PDF field that is as CLOB type already saved in the database.

 

In this second option, can I send the information through the Message property of PutEmail?

In this property, can I join the Email body and attachment? Which one would I have to pass in the PutEmail's Content Type property?

 

If you need any more information, I'm available.

Master Guru

@leandrolinof 
Understand that NiFi wraps all ingested content in to a NiFi FlowFile.  A NiFi FlowFile consists of FlowFile meatdata/attributes (key/value pairs written to the flowfile_repository. NiFi processors can be used to add and modify existing FlowFile Attributes) and FlowFile content (bytes written to a claim within the NiFi content_repository).  Since NiFi is data format agnostic, the FlowFile model allows NiFi to ingest any data format.  This does not mean that NiFi can read/edit all data formats. It is the responsibility of an individual processor that must be designed/coded to operate against specific data types.

While NiFi does not have a purpose built processor specifically for reading PDF, It does ship with scripting processors that can be used to execute custom script code that can extract content from a PDF in to FlowFile attributes.

Reference example:
https://gist.github.com/mattyb149/48e72a26d0f62f330e30

https://stackoverflow.com/questions/55169492/nifi-extract-from-pdf-to-text

I assume since that directory contains multiple PDF, each of those PDF have a unique name?
Once you have ingested your PDFs, the above example groovy script may allow you to create attributes on your FlowFile which you can use later via NiFi Expression Language statements to dynamically set configuration properties on the putEmail processor uniquely by FlowFile it executes upon.
When you look a processor's documentation for each configuration property, you will see if it supports NiFi Expression language and to what extent it is supported

Supports Expression Language: true (will be evaluated using flow file attributes)

Example above states NiFi Expression language is supported and you can use FlowFile attributes which would come from each FlowFile that processor is executing against.

If you can extract the needed text from each PDF in to additional attributes on each FlowFile (one FlowFile created for each PDF ingested) with buyer name, then you can use those to dynamically define properties per FlowFile in the PutEmail processor.

If you desire is to consume every PDF only once, you should be using the ListFile --> FetchFile processors.  The ListFile can be configured to maintain state so that the same FlowFiles are not listed more than once. (ListFile must be configured for "primary node" execution only in a multi-node NiFi cluster setup to avoid data duplication).

The message body of an email is going to expect that message to ASCII text. The "Content Type" property of the PutEmail processor is expected to be set to the content' mime type (for a PDF file the mime.type would be "application/pdf"); however, i suspect the putEmail processor may have issue with that mime.type.  If that is the case, you'll need to send you PDF as attachments to the email only.

I am not sure what the "buyer's ID" gets you.  Is that buyer's ID in the PDF filename?  How does the buyer's ID get you the buyer's email address to which you will send the PDF via PutEmail?

to answer you question about is it possible, I believe so.  It is about collecting/creating the needed metadata/attributes from 1 or more sources and adding them to your FlowFile with the PDF content needed to successfully send your email.

I hope above gets you moving along that path.  NiFi offers so many components, there is often more than one may to solve a use case.  First step is laying out a step by step processor for how you would solve this use case outside NiFi manually and then translate each of those steps in to automated NiFi dataflow.  Then you can narrow down to the specific step in that use case where help is needed further.

If you found that the provided solution(s) assisted you with your query, please take a moment to login and click Accept as Solution below each response that helped.

Thank you,

Matt

Contributor

@Matt 

 

thank you very much for all the answer.

 

We are still insisting on getting the Base64 field from Oracle because the PDF is already there.


I'm using the Base64EncodeContent process to decode the Base64 field coming from Oracle.

 

I was able to send a file to the E-mail with PDF format, but it still has an error when opening the PDF file sent in the E-mail.

 

It seems to me that Nifi cannot say that the code it is decoding from the Base64 field that is coming from Oracle. Sorry for the lack of knowledge on the subject.

 

 

leandrolinof_0-1663943864013.png

 

ExecuteSQL

leandrolinof_1-1663943957036.png

 

UpdateAttribute

leandrolinof_2-1663944030973.png

 

Base64EncodeContent

leandrolinof_3-1663944051290.png

 

PutEmail 

leandrolinof_4-1663944169772.png

 

PutEmail 

leandrolinof_5-1663944204187.png