I there a way to trigger Java code execution when an email is recieved?

Posted on 2004-03-30
Last Modified: 2013-11-24
I found some links about connecting to mail servers and retrieving messages.  However, it would be really nice to automate it, so that code is executed when an email is recieved.  Is it possible, and if so - how?  

Thank you.
Question by:AlexRS78
  • 3
  • 3
LVL 11

Expert Comment

ID: 10721127
What platform? In unix the standard solution is to use procmail
LVL 30

Expert Comment

by:Mayank S
ID: 10723180
>> What platform?

Doesn't matter because he is using Java: >> I there a way to trigger Java code execution when an email is recieved?

You can use the Java Mail API.

Author Comment

ID: 10723490
I've checked the Java mail API - could not find anything that would do that.  There are ways to retrieve messages and such, but nothing that would trigger stuff on email reciept.  It is all connect-do stuff-disconnect....  

Since we're talking about the mail server triggering the code execution, I would think that it is important which platform/mail server is used though...  We're at the design stage at this point, just looking at some options.  They could go with MS Exchange or Unix-based mail servers, not sure yet.  
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

LVL 11

Expert Comment

ID: 10723576
That's why I asked for the platform.
Only your MDA (mail delivery agent) can trigger the execution of your code upon message arrival. Under unix the most common MDA is procmail.
If you don't have any MDA (normal when mail is not stored locally), then your only solution is to periodically poll the mail server and see if new messages have arrived.

Author Comment

ID: 10723648
Can you please explain procmail a little further?  Is it a mail server app, or just an add-in sort of thing?  I am mostly MS, so I'm kind of lost here.  I'll most likely need to explain people how this would work though.

LVL 11

Accepted Solution

lbertacco earned 500 total points
ID: 10723841
The MDA is the process that dispatch mails to users on systems with a mail server.
In a unix machine with an MTA running (MTA is mail transfer agent, the most common of which are sendmail, postfix, exchange) running, the MTA receives the mail, then pass it to and MDA (procmail) which in turn puts it in the user mailboxe.
Anyway this is what happens on machines that are mail servers (which can be translated in : having an SMTP server receiving mail).
It's much more common to have emails kept on some remote host and just use an email client to retrive that via POP or IMAP. In this case there is no other way than periodically poll the remote system to see if new email have arrived.
Of course, if you can configure the remote system at your pleasure, you can configure it to run a small local program upon email arrival and make this small program simply notify your machine that there is new mail.

Author Comment

ID: 10723859
Thanks a lot!

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 95
splitOdd10 challenge 5 104
starter POM and spring-boot-starter,  spring-boot-web 2 54
login jsp example 24 46
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to implement Singleton Design Pattern in Java.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question