0

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.

Thorsten Schöning
  • 3,501
  • 2
  • 25
  • 46

1 Answers1

0

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.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40
  • On platforms like Windows a local mail daemon might not be available, while something like `sendmail.exe` is often mentioned in docs of apps as an easy workaround. I'm using that in other parts of my software as well already and thought if it makes sense to somehow make it available to `javax.mail`. – Thorsten Schöning Apr 22 '20 at 09:47