问题描述
我正在使用JavaMail,并且希望它通过代理处理每个线程(我有多线程应用程序).我正在为此使用SMTPTransport.connect(Socket socket).
I'm using JavaMail and I want it to work through proxy for every threads (I have multithreading application). I'm using SMTPTransport.connect(Socket socket) for this.
这是套接字初始化:
socket = new Socket();
socket.setSoTimeout(10000);
socket.connect(new InetSocketAddress(smtpHost, smtpPort));
这是SMTPTransport呼叫:
Here is SMTPTransport call:
SMTPTransport transport = null;
try
{
transport = (SMTPTransport) mail.getTransport("smtp");
transport.connect(socket);
System.out.println("ok");
以此类推.但是我发生了这个错误:
And so on. But I this error happens:
因此,我看到JavaMail无法从套接字读取.那我在做什么错?如果我尝试在构造函数中不使用Socket的情况下使用transport.connect()方法,那么它们都可以正常工作,并且可以从telnet访问smtpHost/smtpPort,并且我没有任何防火墙/防病毒软件.
So as I see JavaMail can't read from socket. So what am I doing wrong? If I try to use transport.connect() method without using Socket in constructor all works perfectly and smtpHost/smtpPort are accessible from the telnet and I have no any firewalls/antiviruses.
推荐答案
来自com.sun.mail.smtp.SMTPTransport的文档:
From the documentation for com.sun.mail.smtp.SMTPTransport:
警告:应考虑此软件包独有的API 实验性的.将来可能会以下列方式更改它们 与使用当前API的应用程序不兼容.
WARNING: The APIs unique to this package should be considered EXPERIMENTAL. They may be changed in the future in ways that are incompatible with applications using the current APIs.
JavaMail教程: http://java.sun.com/developer/onlineTraining /JavaMail/contents.html
JavaMail tutorial: http://java.sun.com/developer/onlineTraining/JavaMail/contents.html
可能是您没有传递身份验证信息.可能是您正在使用普通套接字连接到受保护的主机.您可能需要阅读链接的教程,以获得使用JavaMail的最佳方法.
Could be you are not passing authentication information. Could be you are connecting to a secured host using a plain socket. You might want to read the tutorial linked for the best way to use JavaMail.
这篇关于JavaMail:套接字读取超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!