<p>Just got a request from my boss for an application I'm working on. Basically we're getting an email address setup for an external client to submit excel files to. </p>

<p>What I need is a way to automatically pick up any email sent to this address, so I can take the attachment, process it and save it to a folder.</p>

<p>Any information of even where to start would be helpful.\</p>

<p>Note: We're using a lotus notes server to do this, but a generic way would be more helpful (If possible).</p>

[{'answer_id': 56743, 'author': 'svrist', 'author_id': 86, 'author_profile': 'https://Stackoverflow.com/users/86', 'pm_score': 4, 'selected': True, 'text': '<p>Email -> mailserver ->[something] -> file-on-disk.</p>\n\n<p>File on disk is pretty easy to parse, use <a href="http://java.sun.com/products/javamail/javadocs/javax/mail/package-summary.html" rel="noreferrer">JavaMail</a>.</p>\n\n<p>The [something] could be:</p>\n\n<ul>\n<li>listener for smtp connections (overkill)!</li>\n<li><a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/pop3/package-summary.html" rel="noreferrer">Pop3</a>/<a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/imap/package-summary.html" rel="noreferrer">imap</a> client</li>\n<li><a href="http://en.wikipedia.org/wiki/Maildir" rel="noreferrer">Maildir</a>/Mailbox</li>\n</ul>\n'}, {'answer_id': 64192, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Lotus Notes/Domino stores mail in a Notes database.  There are APIs available for getting documents (emails), reading field values (From, Subject), and detaching files.</p>\n\n<p>APIs include</p>\n\n<p>-LotusScript (VB variant, available within the Notes database)</p>\n\n<p>-Java (from within or external to the database)</p>\n\n<p>-C API (external)</p>\n\n<p>-Same API available through COM server</p>\n\n<p>You can create a "scheduled agent" within the database (using LotusScript or Java) that can locate documents created since it last ran, locate the attachments, and extract them.  The agent will need to be signed with an ID that has the appropriate permissions on the server, including those required to write to the file system and initiate any other processes.</p>\n\n<p>External to the database, you can use any API except LotusScript to log-in to the server/mail database, and follow a similar process, e.g. extracting the files locally on a client or separate server.  C API and COM require a notes client install, but Java applications can be set up to run via CORBA/DIIOP without a full install.</p>\n\n<p>Consult the Domino Designer help (or IBM\'s website for C API) for more information.</p>\n\n<p>As to a "generic way" to do this, if you are accessing data in Notes and needing to extract attachments, I believe these APIs are your best option.  If you envision porting the application to another mail system, consider decoupling the API routines via an "interface" so you only need to add a new implementation of that interface to support a new mail system.</p>\n'}, {'answer_id': 64286, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>You can access Notes Documents relatively easily using DIIOP, would be a lot easier than going down the C Api road...</p>\n'}, {'answer_id': 71353, 'author': 'AndrewB', 'author_id': 11770, 'author_profile': 'https://Stackoverflow.com/users/11770', 'pm_score': 1, 'selected': False, 'text': "<p>I've done quite a bit lately with Java agents on Domino servers. The Domino 8.5 server supports Java 6 and its embedded so it won't take someone with a bit of Domino development experience long to put together an agent that runs when new mail arrives. In LotusScript its even easier but that needs more specialised skills which you'd probably need to get a contractor in to provide.</p>\n\n<p>The limitation your likely to encounter concerns the extracted file, you can easily place it on the Domino server's file structure but you may be limited by the OS security from placing it on a different server.</p>\n"}, {'answer_id': 74450, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Try POP3Client in the <a href="http://commons.apache.org/net/" rel="nofollow noreferrer">Net Commons package</a>; it\'ll let your Java program check for new mail for a particular account at whatever interval you want (every few minutes?  hourly?), and get/delete messages as desired.</p>\n'}, {'answer_id': 76684, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Use a mail in database (your Domino administrator can set that up for you but it\'s in the help file as well).</p>\n\n<p>In that database, you can create an agent that runs periodically to process all new documents.  That agent will use the EmbeddedObjects property of the NotesRichTextItem class and the ExtractFile method of the NotesEmbeddedObject class to get a handle on the file attachment and extract it to the location you specify.</p>\n\n<p>For example, this script goes through all the file attachments, object links, and embedded objects in the Body item of a document. Each time it finds a file attachment, it detaches the file to the SAMPLES directory on the C drive and removes the attachment from the document</p>\n\n<pre><code>Dim doc As NotesDocument\nDim rtitem As Variant\n\'...set value of doc...\nSet rtitem = doc.GetFirstItem( "Body" )\nIf ( rtitem.Type = RICHTEXT ) Then\n  Forall o In rtitem.EmbeddedObjects\n    If ( o.Type = EMBED_ATTACHMENT ) Then\n      Call o.ExtractFile( "c:\\samples\\" &amp; o.Source )\n      Call o.Remove\n      Call doc.Save( False, True )\n    End If\n  End Forall\nEnd If\n</code></pre>\n'}, {'answer_id': 76778, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>SMTP/POP3 can be enabled on the Domino server.  Worked with this before and gotten Squirrel Mail running with it. SMTP is a bit resource intensive, but well worth the effort because then you don\'t have to descend into LotusLand to get things working.  Just write a small Java CLI program that will check a specific email box (POP3 or SMTP), and parse through the messages, pulling the attachments and placing them where needed.</p>\n\n<p>Plenty of documentation and examples here:\n<a href="http://java.sun.com/products/javamail/" rel="nofollow noreferrer">http://java.sun.com/products/javamail/</a></p>\n\n<p>The techniques that you develop taking this approach will be more widely applicable in your future career than anything Lotus/Domino specific.</p>\n'}, {'answer_id': 278289, 'author': 'DaveB', 'author_id': 36223, 'author_profile': 'https://Stackoverflow.com/users/36223', 'pm_score': 0, 'selected': False, 'text': "<p>No matter what you do, you'll need an understanding of the Lotus Notes data structures.  The good news is that a fully automated solution can be built in Notes very easily.</p>\n\n<p>Your best bet is to have it built within Notes, and it can be set up to run automatically whenever new mail is received.   Gary's answer is dead on, but without any experience, it would probably be hard to figure out how to implement it yourself.  On the other hand, it really shouldn't take any competent Notes programmer more than an hour or two to set it up.</p>\n"}, {'answer_id': 278314, 'author': 'Dan Vinton', 'author_id': 21849, 'author_profile': 'https://Stackoverflow.com/users/21849', 'pm_score': 2, 'selected': False, 'text': '<p><em>Edit:</em> since I first wrote this answer, Wiser has moved and now claims to only be a unit testing tool, so take the answer below with a pinch of salt...</p>\n\n<hr>\n\n<p>Svrist\'s answer is good, but if you want to avoid his middle step (the mailserver that writes the mail to disk for later pickup by the Java system) you can use <a href="http://code.google.com/p/subethasmtp/wiki/Wiser" rel="nofollow noreferrer">Wiser</a>.</p>\n\n<p>Wiser lets you start an in-Java mailserver:</p>\n\n<pre><code>Wiser wiser = new Wiser();\nwiser.setPort(2500);\nwiser.start();\n</code></pre>\n\n<p>Then you can just poll it periodically for mail:</p>\n\n<pre><code>for (WiserMessage message : wiser.getMessages())\n{\n    String envelopeSender = message.getEnvelopeSender();\n    String envelopeReceiver = message.getEnvelopeReceiver();\n\n    MimeMessage mess = message.getMimeMessage();\n\n    // mail processing goes here\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/56722', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1419/']