Reputation: 2117
I'm able to look up network interfaces using java.net.NetworkInterface:
ni = NetworkInterface.getByName("eth4");
Is there a way to request that JavaMail send mail, using SMTP transport, via a specific interface?
Upvotes: 2
Views: 859
Reputation: 29971
You can set the mail.smtp.localaddress property to the host name corresponding to a particular interface to bind to that interface. Use NetworkInterface.getInetAddresses and look for an Inet4Address.
Upvotes: 5
Reputation: 41133
I don't think your question made any sense at all. When you're sending email via SMTP, you have to choose a SMTP host (either an IP address or a DNS alias name which will then be resolved to an IP address). Your OS will then pick which network interface to use based on the configured routing table.
Routing IP address to an interface doesn't sound like an application layer job at all.
Upvotes: 0