Automatic Email Processing in Java

I just received a request from my boss for the application I'm working on. Basically we get the email address setting for an external client to send excel files.

What I need is to automatically receive any email address sent to this address, so I can take the attachment, process it and save it in a folder.

Any information, even where to start, would be helpful. \

Note. We use the Lotus Notes server for this, but a general way would be more useful (if possible).

+4
source share
9 answers

Email → mailserver → [something] → file-on-disk.

The file on disk is pretty easy to parse, use JavaMail .

[something] could be:

  • listener for smtp connections (overkill)!
  • Pop3 / imap client
  • Maildir / Mailbox
+9
source

Edit: since I first wrote this answer, Wiser moved and now only claims to be a single testing tool, so take the answer below with a little salt ...


Svrist's answer is good, but if you want to avoid its middle step (a mail server that writes mail to disk for later invocation by the Java system), you can use Wiser .

Wiser allows you to run the mail server in Java:

Wiser wiser = new Wiser(); wiser.setPort(2500); wiser.start(); 

Then you can simply poll it periodically for mail:

 for (WiserMessage message : wiser.getMessages()) { String envelopeSender = message.getEnvelopeSender(); String envelopeReceiver = message.getEnvelopeReceiver(); MimeMessage mess = message.getMimeMessage(); // mail processing goes here } 
+2
source

Recently, I have worked a bit with Java agents on Domino servers. Domino 8.5 server supports Java 6 and its built-in interface, so it doesn’t take anyone a bit of Domino development experience to build an agent that starts when new mail arrives. In LotusScript, this is even easier, but it requires more specialized skills, which you probably need to provide to the contractor.

The limitation that you may encounter is related to the extracted file, you can easily place it in the file structure of the Domino server, but you can be limited by protecting the OS from being placed on another server.

+1
source

Use mail in the database (the Domino administrator can set this for you, but also in the help file).

In this database, you can create an agent that periodically starts processing all new documents. This agent will use the EmbeddedObjects property of the NotesRichTextItem class and the ExtractFile method of the NotesEmbeddedObject class to get the file attachment descriptor and extract it to the location you specify.

For example, this script looks through all file attachments, object references, and embedded objects in the Body element of a document. Each time it finds a file attachment, it separates the file in the SAMPLES directory on drive C and removes the attachment from the document

 Dim doc As NotesDocument Dim rtitem As Variant '...set value of doc... Set rtitem = doc.GetFirstItem( "Body" ) If ( rtitem.Type = RICHTEXT ) Then Forall o In rtitem.EmbeddedObjects If ( o.Type = EMBED_ATTACHMENT ) Then Call o.ExtractFile( "c:\samples\" & o.Source ) Call o.Remove Call doc.Save( False, True ) End If End Forall End If 
+1
source

Lotus Notes / Domino stores mail in the Notes database. APIs are available for receiving documents (emails), reading field values ​​(From, Subject) and disconnecting files.

APIs include

-LotusScript (VB option available in the Notes database)

-Java (inside or outside the database)

-C API (external)

- API available through the COM server

You can create a “scheduled agent” in the database (using LotusScript or Java) that can find documents created since the last run, find attachments and extract them. The agent must be signed with an identifier that has the appropriate permissions on the server, including those necessary to write to the file system and initiate any other processes.

External access to the database, you can use any API except LotusScript to enter the server / mail database and follow a similar process, for example. Extract files locally on the client or on a separate server. The C API and COM require the installation of the client notes, but Java applications can be configured to run through CORBA / DIIOP without a full installation.

For more information, see the Domino Designer help (or the IBM website for API C).

As for the “general way” for this, if you are accessing data in Notes and need to extract attachments, I think these APIs are your best option. If you plan to port the application to another mail system, consider unbinding the API routines through an “interface”, so you only need to add a new implementation of this interface to support the new mail system.

0
source

You can easily access Notes documents relatively easily using DIIOP, it would be much easier than going down the C Api road ...

0
source

Try POP3Client in Net Commons package ; this will allow your Java program to check new mail for a specific account at any time (every few minutes? hourly?) and receive / delete messages as desired.

0
source

SMTP / POP3 can be enabled on the Domino server. Worked with this before and got Squirrel Mail working with it. SMTP is a resource-intensive resource, but it's worth it that you don’t have to go down to LotusLand to get everything working. Just write a small Java CLI program that will check a specific mailbox (POP3 or SMTP) and parse messages, pull attachments and place them where necessary.

Here is a lot of documentation and examples: http://java.sun.com/products/javamail/

The methods that you develop using this approach will be more widely applied in your future career than anything specific Lotus / Domino.

0
source

No matter what you do, you need an understanding of Lotus Notes data structures. The good news is that a fully automated solution can be easily created in Notes.

It’s best to create it in Notes, and you can configure it to start automatically when you receive new mail. Gary's answer is dead, but without any experience, it will probably be difficult to figure out how to implement it yourself. On the other hand, you really don't need to take any Notes programmers for more than an hour or two to set it up.

0
source

Source: https://habr.com/ru/post/1276648/


All Articles