Workaround '501 Syntactically invalid HELO argument(s)'

pull/172/head
M66B 6 years ago
parent afbcd2dc69
commit b82f10dd80

@ -364,10 +364,9 @@ public class MailService implements AutoCloseable {
} else if ("smtp".equals(protocol) || "smtps".equals(protocol)) { } else if ("smtp".equals(protocol) || "smtps".equals(protocol)) {
String[] c = BuildConfig.APPLICATION_ID.split("\\."); String[] c = BuildConfig.APPLICATION_ID.split("\\.");
Collections.reverse(Arrays.asList(c)); Collections.reverse(Arrays.asList(c));
String domain = TextUtils.join(".", c); String hdomain = TextUtils.join(".", c);
String haddr = domain; String haddr = "[127.0.0.1]";
if (useip)
try { try {
// This assumes getByName always returns the same address (type) // This assumes getByName always returns the same address (type)
InetAddress addr = InetAddress.getByName(host); InetAddress addr = InetAddress.getByName(host);
@ -380,17 +379,16 @@ public class MailService implements AutoCloseable {
} }
Log.i("Using localhost=" + haddr); Log.i("Using localhost=" + haddr);
properties.put("mail." + protocol + ".localhost", haddr); properties.put("mail." + protocol + ".localhost", useip ? haddr : hdomain);
iservice = isession.getTransport(protocol); iservice = isession.getTransport(protocol);
try { try {
iservice.connect(host, port, user, password); iservice.connect(host, port, user, password);
} catch (MessagingException ex) { } catch (MessagingException ex) {
if (useip && if (ex.getMessage() != null &&
ex.getMessage() != null &&
ex.getMessage().toLowerCase().contains("syntactically invalid")) { ex.getMessage().toLowerCase().contains("syntactically invalid")) {
Log.w("Using localhost=" + domain, ex); Log.w("Using localhost=" + (useip ? hdomain : haddr), ex);
((SMTPTransport) iservice).setLocalHost(domain); ((SMTPTransport) iservice).setLocalHost(useip ? hdomain : haddr);
iservice.connect(host, port, user, password); iservice.connect(host, port, user, password);
} else } else
throw ex; throw ex;

Loading…
Cancel
Save