This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push:
new fb0bce5 JAMES-3645 Allow RemoteDelivery to use SMTPS and fallback to
SMTP (#632)
fb0bce5 is described below
commit fb0bce58c898c8f3b3301450cccfed44c2d1e0fc
Author: Benoit TELLIER <[email protected]>
AuthorDate: Mon Sep 13 08:18:20 2021 +0700
JAMES-3645 Allow RemoteDelivery to use SMTPS and fallback to SMTP (#632)
---
docs/modules/servers/partials/RemoteDelivery.adoc | 3 ++-
.../james/dnsservice/library/MXHostAddressIterator.java | 16 +++++++++-------
.../apache/james/transport/mailets/RemoteDelivery.java | 3 ++-
.../mailets/remote/delivery/MailDelivrerToHost.java | 1 -
4 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/docs/modules/servers/partials/RemoteDelivery.adoc
b/docs/modules/servers/partials/RemoteDelivery.adoc
index daa9f12..89ab13c 100644
--- a/docs/modules/servers/partials/RemoteDelivery.adoc
+++ b/docs/modules/servers/partials/RemoteDelivery.adoc
@@ -38,7 +38,8 @@ be delivered to for DSN bounce processing. Default is to send
a traditional mess
* *startTLS* (optional) - a Boolean (true/false) indicating whether the
STARTTLS command (if supported by the server)
to switch the connection to a TLS-protected connection before issuing any
login commands. Default is false.
* *sslEnable* (optional) - a Boolean (true/false) indicating whether to use
SSL to connect and use the SSL port unless
-explicitly overridden. Default is false.
+explicitly overridden. Default is false. Setting up to true will result in
delivery attempts in SMTPS on port 465 with a fallback
+to SMTP on port 25. The trust-store if needed can be customized by
*-Djavax.net.ssl.trustStore=/root/conf/keystore*.
* *gateway* (optional) - a String containing a comma separated list of
patterns defining the gateway servers to be used to
deliver mail regardless of the recipient address. If multiple gateway servers
are defined, each will be tried in definition order
until delivery is successful. If none are successful, the mail is bounced. The
pattern is *host[:port]* where:
diff --git
a/server/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java
b/server/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java
index ad1d1b0..feb36ee 100644
---
a/server/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java
+++
b/server/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java
@@ -26,6 +26,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import org.apache.james.dnsservice.api.DNSService;
import org.apache.mailet.HostAddress;
@@ -59,7 +60,8 @@ public class MXHostAddressIterator implements
Iterator<HostAddress> {
while (hosts.hasNext()) {
String nextHostname = hosts.next();
- Map.Entry<String, String> hostAndPort =
extractHostAndPort(nextHostname, 25);
+
+ Map.Entry<String, Optional<String>> hostAndPort =
extractHostAndPort(nextHostname);
try {
final Collection<InetAddress> addrs;
@@ -71,10 +73,10 @@ public class MXHostAddressIterator implements
Iterator<HostAddress> {
for (InetAddress addr : addrs) {
if (smtps) {
hAddresses.add(new HostAddress(hostAndPort.getKey(),
- "smtps://" + addr.getHostAddress() + ":465"));
+ "smtps://" + addr.getHostAddress() + ":" +
hostAndPort.getValue().orElse("465")));
}
hAddresses.add(new HostAddress(hostAndPort.getKey(),
- "smtp://" + addr.getHostAddress() + ":25"));
+ "smtp://" + addr.getHostAddress() + ":" +
hostAndPort.getValue().orElse("25")));
}
} catch (UnknownHostException uhe) {
// this should never happen, since we just got
@@ -87,17 +89,17 @@ public class MXHostAddressIterator implements
Iterator<HostAddress> {
addresses = hAddresses.iterator();
}
- private static ImmutableMap.Entry<String, String>
extractHostAndPort(String nextHostname, int defaultPort) {
+ private static ImmutableMap.Entry<String, Optional<String>>
extractHostAndPort(String nextHostname) {
final String hostname;
- final String port;
+ final Optional<String> port;
int idx = nextHostname.indexOf(':');
if (idx > 0) {
- port = nextHostname.substring(idx + 1);
+ port = Optional.of(nextHostname.substring(idx + 1));
hostname = nextHostname.substring(0, idx);
} else {
hostname = nextHostname;
- port = Integer.toString(defaultPort);
+ port = Optional.empty();
}
return Maps.immutableEntry(hostname, port);
}
diff --git
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
index 5cb3889..130267d 100644
---
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
+++
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
@@ -86,7 +86,8 @@ import com.google.common.collect.HashMultimap;
* <li><b>startTLS</b> (optional) - a Boolean (true/false) indicating whether
the STARTTLS command (if supported by the server)
* to switch the connection to a TLS-protected connection before issuing any
login commands. Default is false.</li>
* <li><b>sslEnable</b> (optional) - a Boolean (true/false) indicating whether
to use SSL to connect and use the SSL port unless
- * explicitly overridden. Default is false.</li>
+ * explicitly overridden. Default is false. The trust-store if needed can be
customized by
+ * <strong>-Djavax.net.ssl.trustStore=/root/conf/keystore</strong>.</li>
* <li><b>gateway</b> (optional) - a String containing a comma separated list
of patterns defining the gateway servers to be used to
* deliver mail regardless of the recipient address. If multiple gateway
servers are defined, each will be tried in definition order
* until delivery is successful. If none are successful, the mail is bounced.
The pattern is <code>host[:port]</code> where:
diff --git
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/MailDelivrerToHost.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/MailDelivrerToHost.java
index cac6353..9b3ca01 100644
---
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/MailDelivrerToHost.java
+++
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/MailDelivrerToHost.java
@@ -106,7 +106,6 @@ public class MailDelivrerToHost {
}
private Session selectSession(HostAddress host) {
- System.out.println("___________ " + host.getProtocol());
if (host.getProtocol().equalsIgnoreCase("smtps")) {
return smtpsSession;
} else {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]