mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
Issue 1303: can't send mail get "no route to host" error
This commit is contained in:
parent
21c9c6c1dc
commit
696666ca5e
@ -9,6 +9,7 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
@ -2132,24 +2133,36 @@ public class ImapStore extends Store {
|
|||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// -> try all IPv4 and IPv6 addresses of the host.
|
||||||
SocketAddress socketAddress = new InetSocketAddress(mSettings.getHost(), mSettings.getPort());
|
int mConnectionSecurity = mSettings.getConnectionSecurity();
|
||||||
|
InetAddress[] addresses = InetAddress.getAllByName(mSettings.getHost());
|
||||||
if (K9.DEBUG)
|
for (int i = 0; i < addresses.length; i++) {
|
||||||
Log.i(K9.LOG_TAG, "Connection " + getLogId() + " connecting to " + mSettings.getHost() + " @ IP addr " + socketAddress);
|
try {
|
||||||
|
if (K9.DEBUG && K9.DEBUG_PROTOCOL_IMAP) {
|
||||||
if (mSettings.getConnectionSecurity() == CONNECTION_SECURITY_SSL_REQUIRED ||
|
Log.d(K9.LOG_TAG, "connecting to " + mSettings.getHost() + " as " + addresses[i]);
|
||||||
mSettings.getConnectionSecurity() == CONNECTION_SECURITY_SSL_OPTIONAL) {
|
}
|
||||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
SocketAddress socketAddress = new InetSocketAddress(addresses[i], mSettings.getPort());
|
||||||
final boolean secure = mSettings.getConnectionSecurity() == CONNECTION_SECURITY_SSL_REQUIRED;
|
if (mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED ||
|
||||||
sslContext.init(null, new TrustManager[] {
|
mConnectionSecurity == CONNECTION_SECURITY_SSL_OPTIONAL) {
|
||||||
TrustManagerFactory.get(mSettings.getHost(), secure)
|
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||||
}, new SecureRandom());
|
boolean secure = mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED;
|
||||||
mSocket = sslContext.getSocketFactory().createSocket();
|
sslContext.init(null, new TrustManager[] {
|
||||||
mSocket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
|
TrustManagerFactory.get(mSettings.getHost(), secure)
|
||||||
} else {
|
}, new SecureRandom());
|
||||||
mSocket = new Socket();
|
mSocket = sslContext.getSocketFactory().createSocket();
|
||||||
mSocket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
|
mSocket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
|
||||||
|
} else {
|
||||||
|
mSocket = new Socket();
|
||||||
|
mSocket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
|
||||||
|
}
|
||||||
|
} catch (SocketException e) {
|
||||||
|
if (i < (addresses.length - 1)) {
|
||||||
|
// there are still other addresses for that host to try
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw new MessagingException("Cannot connect to host", e);
|
||||||
|
}
|
||||||
|
break; // connection success
|
||||||
}
|
}
|
||||||
|
|
||||||
setReadTimeout(Store.SOCKET_READ_TIMEOUT);
|
setReadTimeout(Store.SOCKET_READ_TIMEOUT);
|
||||||
|
@ -250,7 +250,7 @@ public class SmtpTransport extends Transport {
|
|||||||
mSocket = new Socket();
|
mSocket = new Socket();
|
||||||
mSocket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
|
mSocket.connect(socketAddress, SOCKET_CONNECT_TIMEOUT);
|
||||||
}
|
}
|
||||||
} catch (ConnectException e) {
|
} catch (SocketException e) {
|
||||||
if (i < (addresses.length - 1)) {
|
if (i < (addresses.length - 1)) {
|
||||||
// there are still other addresses for that host to try
|
// there are still other addresses for that host to try
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user