必要なプロキシを使用して独自のソケットを作成する必要があります。
SocketAddress addr = new InetSocketAddress("socks.mydomain.com", 1080);
Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
Socket socket = new Socket(proxy);
InetSocketAddress dest = new InetSocketAddress("smtp.foo.com", 25);
socket.connect(dest);
次に、それを接続に使用します。
SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
transport.connect(socket);
編集:メールを送信するために SMTP サーバーでの認証が必要な場合は注意が必要です。その場合は、サブクラスを作成してメソッドjavax.mail.Authenticator
に渡す必要があります。Session.getInstance()
MyAuthenticator authenticator = new MyAuthenticator();
Properties properties = new Properties();
properties.setProperty("mail.smtp.submitter",
authenticator.getPasswordAuthentication().getUserName());
properties.setProperty("mail.smtp.auth", "true");
Session session = Session.getInstance(properties, authenticator);
オーセンティケーターは次のようになります。
private class MyAuthenticator extends javax.mail.Authenticator
{
private PasswordAuthentication authentication;
public Authenticator()
{
String username = "auth-user";
String password = "auth-password";
authentication = new PasswordAuthentication(username, password);
}
protected PasswordAuthentication getPasswordAuthentication()
{
return authentication;
}
}
これはすべてテストされていませんが、それがあなたがしなければならないすべてだと思います。少なくともあなたを正しい道に導くはずです。