diff --git a/src/common/connection.py b/src/common/connection.py
index a1353e8af8ebc7795bfbaddda27ab9d7aca56f01..f0f90d2513cbe56d0f18d790fc8ae8777bf25486 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -1136,10 +1136,20 @@ class Connection(CommonConnection, ConnectionHandlers):
             else:
                 use_custom = gajim.config.get_per('accounts', self.name,
                     'use_custom_host')
-                custom_h = gajim.config.get_per('accounts', self.name,
-                    'custom_host')
-                custom_p = gajim.config.get_per('accounts', self.name,
-                    'custom_port')
+                if use_custom:
+                    custom_h = gajim.config.get_per('accounts', self.name,
+                        'custom_host')
+                    custom_p = gajim.config.get_per('accounts', self.name,
+                        'custom_port')
+                    try:
+                        helpers.idn_to_ascii(custom_h)
+                    except Exception:
+                        gajim.nec.push_incoming_event(InformationEvent(None,
+                            conn=self, level='error',
+                            pri_txt=_('Wrong Custom Hostname'),
+                            sec_txt='Wrong custom hostname "%s". Ignoring it.' \
+                            % custom_h))
+                        use_custom = False
 
         # create connection if it doesn't already exist
         self.connected = 1