'Validate email id and check POP3/IMAP and SMTP connections is enabled.'

def validate(self):

    if self.email_id:
        validate_email_add(self.email_id, True)
    if (frappe.local.flags.in_patch or frappe.local.flags.in_test):
        return
    if ((not frappe.local.flags.in_install) and (not frappe.local.flags.in_patch)):
        try:
            if self.use_imap:
                if self.use_ssl:
                    test = imaplib.IMAP4_SSL(self.email_server)
                else:
                    test = imaplib.IMAP4(self.email_server)
            elif self.use_ssl:
                test = poplib.POP3_SSL(self.email_server)
            else:
                test = poplib.POP3(self.email_server)
        except Exception:
            frappe.throw(_(u'Incoming    email    account    not    correct'))
            return None
        finally:
            try:
                if self.use_imap:
                    test.logout()
                else:
                    test.quit()
            except Exception:
                pass
        try:
            if (self.use_tls and (not self.smtp_port)):
                self.port = 587
            sess = smtplib.SMTP((self.smtp_server or u'').encode(u'utf-8'), (cint(self.smtp_port) or None))
            sess.quit()
        except Exception:
            frappe.throw(_(u'Outgoing    email    account    not    correct'))
            return None
    return
