Thorsten Schöning
Thorsten Schöning

Reputation: 3707

How to make javax.mail use a local "sendmail" binary?

I'm using javax.mail to create E-Mails and render those to their textual representation. Under certain conditions I don't want to forward those results using SMTP, but e.g. pipe them to a sendmail-binary. That seems to be pretty common in case of shell scripts and I came across this in the Perl-ecosystem as well.

Is something like that supported by javax.mail itself or some additional "plugin" already?

I don't see any such option, only SMTP or different network related protocols. Though, one can additionally implement a custom transport by extending Transport and registering that instead of SMTP in javamail.providers. Looking at the available source code, I see many concepts of hosts, ports, URLs, established connections etc., which doesn't fit local communication using a pipe very well. I wonder if one is able to override default behaviour to not work too network-specific at all.

So, can this approach work for non-network related transports at all or is "Transport" simply not designed that way?

I'f Im already using javax.mail, it might be a good idea to integrate any customization with that as much as reasonable.

Upvotes: 0

Views: 144

Answers (1)

Bill Shannon
Bill Shannon

Reputation: 29961

You should be able to write your own Transport implementation that sends the message to a local sendmail using a pipe, but it's a lot easier to send it to the local sendmail daemon using SMTP; just send it to localhost.

Upvotes: 0

Related Questions