aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes I need a Java package that can receive SMTP traffic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "I need a Java package that can receive SMTP traffic" Watch "I need a Java package that can receive SMTP traffic" New topic
Author

I need a Java package that can receive SMTP traffic

Rob Tanner
Greenhorn

Joined: Apr 10, 2009
Posts: 19
I'm writing a package that sits in front of our primary SMTP server (Postfix) that will route mail either to localhost or another SMTP server based on the sender address. We have two outgoing servers. One handles most all of our outgoing traffic and the other is configured especially to talk to Mandrill, a mailing service of MailChimp. The latter server handles all outgoing traffic originating in our admissions office (aka, the higher ed marketing). The bulk of the mail is generated out of the admissions database that points to this secondary SMTP server. My problem is that admissions counselors often do large mailings through their individual email accounts, so I would like to select the SMTP server to route the mail based on the sender address (which can be looked up easily in LDAP).

I'm familiar with JavaMail for sending mail from programs and I also use it for managing restricted exploder lists as I can check on whether a sender is authorized to send email to that list. But the content is either generated from another program or in the case of exploders, the content is fed in through STDIN. But as far as I know, JavaMail can send but cannot receive mail over SMTP. Are you aware of any package that might meet my needs?

Thanks,

Rob Tanner
Linfield College


Rob Tanner
Linfield College
Mike. J. Thompson
Ranch Hand

Joined: Apr 17, 2014
Posts: 263
    
    5
Rob Tanner wrote:I'm writing a package that sits in front of our primary SMTP server (Postfix) that will route mail either to localhost or another SMTP server based on the sender address. We have two outgoing servers. One handles most all of our outgoing traffic and the other is configured especially to talk to Mandrill, a mailing service of MailChimp. The latter server handles all outgoing traffic originating in our admissions office (aka, the higher ed marketing). The bulk of the mail is generated out of the admissions database that points to this secondary SMTP server. My problem is that admissions counselors often do large mailings through their individual email accounts, so I would like to select the SMTP server to route the mail based on the sender address (which can be looked up easily in LDAP).

I'm familiar with JavaMail for sending mail from programs and I also use it for managing restricted exploder lists as I can check on whether a sender is authorized to send email to that list. But the content is either generated from another program or in the case of exploders, the content is fed in through STDIN. But as far as I know, JavaMail can send but cannot receive mail over SMTP. Are you aware of any package that might meet my needs?

Thanks,

Rob Tanner
Linfield College


I've never used it myself so can't vouch for it, but a quick search found SubEthaSMTP. Is this suitable for your needs?
Rob Tanner
Greenhorn

Joined: Apr 10, 2009
Posts: 19
Another member of the forum suggested that I look at SubEthaSMTP and it looks like it will fit the bill (thanks Mike).

I downloaded the code, built the example from the WIKI (below), added the required jars to my path in Eclipse, added some print statements to display the sender and recipient’s email addresses, and started it up. And I also surrounded the for loop with a while loop to keep it looping indefinitely otherwise it simply falls through and stops. It should according to the explanation on the Wiki page, be listening on port 2500, but when I try to connect everything just times out as if it’s not even listening (if it makes any difference, my Java development is a Mac running Mavericks).

This code is exactly like what's shown in the wiki other than I added the infinite while loop:


Anybody have any ideas because right now I can't even get to first base.

Thanks,

Rob Tanner
Linfield College
Ron McLeod
Ranch Hand

Joined: Feb 12, 2013
Posts: 314
    
    5

Have you looked to see if you can use a MTA like sendmail and configure it to select the appropriate smarthost based on the sending domain?
Rob Tanner
Greenhorn

Joined: Apr 10, 2009
Posts: 19
Sadly, my issue isn't domain specific, it's department specific and everyone is in the same network domain. I need to be able to route all outgoing messages that originate from folks who work in the Admissions office (the marketing division of colleges and universities) to a server that talks exclusively to a re-mailing service where Auth-SMTP is used as part of the handshake. Since every individual with a campus email account has an LDAP entry as well, I need that entry to discover their departmental affiliation and route the message to one server or the other based on that affiliation. I can use Javamail to route the message but I also need some way to receive it.
Ron McLeod
Ranch Hand

Joined: Feb 12, 2013
Posts: 314
    
    5

I haven't looked at this in a long time, but Sendmail or other MTAs have support for milters (external mail filters) which will can be called at various points in the message processing to make handling decisions . You should be able to hook-in and see the MAIL FROM, RCPT TO, client IP address, and other information that you may need to make your routing decision.

There is an open source project called sendmail-jilter which might be worth looking at - I have never used it.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2377
    
  28

Any reason you are doing this in Java? It seems like you need a basic SMTP proxy. There has to be atleast a thousand solutions out there.. and maybe your existing firewall/proxy might have a solution inbuilt

Or if you want something that integrates with Java, you might want to look at Apache James. It's a collection of modules that collectively provide email server functionality. There will probably me something for a SMTP proxy there.
Rob Tanner
Greenhorn

Joined: Apr 10, 2009
Posts: 19
No, it doesn't have to be done in Java. Any package that can to an LDAP search, find the user, retrieve the LDAP entry and make a decision based on department affiliation will do. But if I'm having to write it, it will be in Java.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: I need a Java package that can receive SMTP traffic