From ad07ae8032696805755a4e2c8fc585ff13197bc4 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 8 Jan 2020 11:00:53 +0100 Subject: [PATCH] Auto fix '501 Syntactically invalid HELO argument(s)' --- .../main/java/eu/faircode/email/MailService.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/MailService.java b/app/src/main/java/eu/faircode/email/MailService.java index 9164c96690..5631765abb 100644 --- a/app/src/main/java/eu/faircode/email/MailService.java +++ b/app/src/main/java/eu/faircode/email/MailService.java @@ -345,8 +345,9 @@ public class MailService implements AutoCloseable { } else if ("smtp".equals(protocol) || "smtps".equals(protocol)) { String[] c = BuildConfig.APPLICATION_ID.split("\\."); Collections.reverse(Arrays.asList(c)); - String haddr = TextUtils.join(".", c); + String domain = TextUtils.join(".", c); + String haddr = domain; if (useip) try { // This assumes getByName always returns the same address (type) @@ -363,7 +364,18 @@ public class MailService implements AutoCloseable { properties.put("mail." + protocol + ".localhost", haddr); iservice = isession.getTransport(protocol); - iservice.connect(host, port, user, password); + try { + iservice.connect(host, port, user, password); + } catch (MessagingException ex) { + if (useip && + ex.getMessage() != null && + ex.getMessage().toLowerCase().contains("syntactically invalid")) { + Log.i("Using localhost=" + domain); + properties.put("mail." + protocol + ".localhost", domain); + iservice.connect(host, port, user, password); + } else + throw ex; + } } else throw new NoSuchProviderException(protocol); } catch (MessagingException ex) {