コード例 #1
0
ファイル: generic.py プロジェクト: bdimcheff/sync-engine
    def verify_account(self, account):
        """
        Verifies a generic IMAP account by logging in and logging out to both
        the IMAP/ SMTP servers.

        Note:
        Raises exceptions from connect_account(), SMTPClient._get_connection()
        on error.

        Returns
        -------
        True: If the client can successfully connect to both.

        """
        # Verify IMAP login
        conn = self.connect_account(account)
        info = account.provider_info
        if "condstore" not in info:
            if self._supports_condstore(conn):
                account.supports_condstore = True
        try:
            conn.list_folders()
        except Exception as e:
            log.error("account_folder_list_failed",
                      email=account.email_address,
                      account_id=account.id,
                      error=e.message)
            raise UserRecoverableConfigError("Full IMAP support is not "
                                             "enabled for this account. "
                                             "Please contact your domain "
                                             "administrator and try again.")
        finally:
            conn.logout()

        # Verify SMTP login
        try:
            # Check that SMTP settings work by establishing and closing and
            # SMTP session.
            smtp_client = SMTPClient(account)
            with smtp_client._get_connection():
                pass
        except Exception as exc:
            log.error('Failed to establish an SMTP connection',
                      email=account.email_address,
                      account_id=account.id,
                      error=exc)
            raise UserRecoverableConfigError("Please check that your SMTP "
                                             "settings are correct.")
        return True
コード例 #2
0
ファイル: generic.py プロジェクト: bdimcheff/sync-engine
    def verify_account(self, account):
        """
        Verifies a generic IMAP account by logging in and logging out to both
        the IMAP/ SMTP servers.

        Note:
        Raises exceptions from connect_account(), SMTPClient._get_connection()
        on error.

        Returns
        -------
        True: If the client can successfully connect to both.

        """
        # Verify IMAP login
        conn = self.connect_account(account)
        info = account.provider_info
        if "condstore" not in info:
            if self._supports_condstore(conn):
                account.supports_condstore = True
        try:
            conn.list_folders()
        except Exception as e:
            log.error("account_folder_list_failed",
                      email=account.email_address,
                      account_id=account.id,
                      error=e.message)
            raise UserRecoverableConfigError("Full IMAP support is not "
                                             "enabled for this account. "
                                             "Please contact your domain "
                                             "administrator and try again.")
        finally:
            conn.logout()

        # Verify SMTP login
        try:
            # Check that SMTP settings work by establishing and closing and
            # SMTP session.
            smtp_client = SMTPClient(account)
            with smtp_client._get_connection():
                pass
        except Exception as exc:
            log.error('Failed to establish an SMTP connection',
                      email=account.email_address,
                      account_id=account.id,
                      error=exc)
            raise UserRecoverableConfigError("Please check that your SMTP "
                                             "settings are correct.")
        return True
コード例 #3
0
def test_smtp_connection(settings):
    has_starttls = ('aol' in settings['settings']['smtp_server_host'])

    if has_starttls:
        account = _create_account(settings, ssl=True)
        smtp_client = SMTPClient(account)
        with smtp_client._get_connection():
            pass
    else:
        account = _create_account(settings, ssl=True)
        smtp_client = SMTPClient(account)
        with pytest.raises(SendMailException):
            with smtp_client._get_connection():
                pass
        account = _create_account(settings, ssl=False)
        smtp_client = SMTPClient(account)
        with smtp_client._get_connection():
            pass
コード例 #4
0
ファイル: test_ssl_auth.py プロジェクト: aabde/sync-engine
def test_smtp_connection(settings):
    has_starttls = ('aol' in settings['settings']['smtp_server_host'])

    if has_starttls:
        account = _create_account(settings, ssl=True)
        smtp_client = SMTPClient(account)
        with smtp_client._get_connection():
            pass
    else:
        account = _create_account(settings, ssl=True)
        smtp_client = SMTPClient(account)
        with pytest.raises(SendMailException):
            with smtp_client._get_connection():
                pass
        account = _create_account(settings, ssl=False)
        smtp_client = SMTPClient(account)
        with smtp_client._get_connection():
            pass
コード例 #5
0
ファイル: generic.py プロジェクト: macoto-liu/sync-engine
    def verify_account(self, account):
        """
        Verifies a generic IMAP account by logging in and logging out to both
        the IMAP/ SMTP servers.

        Note:
        Raises exceptions from connect_account(), SMTPClient._get_connection()
        on error.

        Returns
        -------
        True: If the client can successfully connect to both.

        """
        # Verify IMAP login
        conn = self.connect_account(account)
        crispin = CrispinClient(account.id, account.provider_info,
                                account.email_address, conn)

        info = account.provider_info
        if "condstore" not in info:
            if self._supports_condstore(conn):
                account.supports_condstore = True
        try:
            conn.list_folders()
            account.folder_separator = crispin.folder_separator
            account.folder_prefix = crispin.folder_prefix
        except Exception as e:
            log.error("account_folder_list_failed",
                      account_id=account.id,
                      error=e.message)
            error_message = (
                "Full IMAP support is not enabled for this account. "
                "Please contact your domain "
                "administrator and try again.")
            raise UserRecoverableConfigError(error_message)
        finally:
            conn.logout()

        # Verify SMTP login
        try:
            # Check that SMTP settings work by establishing and closing and
            # SMTP session.
            smtp_client = SMTPClient(account)
            with smtp_client._get_connection():
                pass
        except socket.gaierror as exc:
            log.error('Failed to resolve SMTP server domain',
                      account_id=account.id,
                      error=exc)
            error_message = (
                "Couldn't resolve the SMTP server domain name. "
                "Please check that your SMTP settings are correct.")
            raise UserRecoverableConfigError(error_message)

        except socket.timeout as exc:
            log.error('TCP timeout when connecting to SMTP server',
                      account_id=account.id,
                      error=exc)

            error_message = (
                "Connection timeout when connecting to SMTP server. "
                "Please check that your SMTP settings are correct.")
            raise UserRecoverableConfigError(error_message)

        except Exception as exc:
            log.error('Failed to establish an SMTP connection',
                      smtp_endpoint=account.smtp_endpoint,
                      account_id=account.id,
                      error=exc)
            raise UserRecoverableConfigError("Please check that your SMTP "
                                             "settings are correct.")

        # Reset the sync_state to 'running' on a successful re-auth.
        # Necessary for API requests to proceed and an account modify delta to
        # be returned to delta/ streaming clients.
        # NOTE: Setting this does not restart the sync. Sync scheduling occurs
        # via the sync_should_run bit (set to True in update_account() above).
        account.sync_state = ('running'
                              if account.sync_state else account.sync_state)
        return True
コード例 #6
0
ファイル: generic.py プロジェクト: nylas/sync-engine
    def verify_account(self, account):
        """
        Verifies a generic IMAP account by logging in and logging out to both
        the IMAP/ SMTP servers.

        Note:
        Raises exceptions from connect_account(), SMTPClient._get_connection()
        on error.

        Returns
        -------
        True: If the client can successfully connect to both.

        """
        # Verify IMAP login
        conn = self.connect_account(account)
        crispin = CrispinClient(account.id, account.provider_info,
                                account.email_address, conn)

        info = account.provider_info
        if "condstore" not in info:
            if self._supports_condstore(conn):
                account.supports_condstore = True
        try:
            conn.list_folders()
            account.folder_separator = crispin.folder_separator
            account.folder_prefix = crispin.folder_prefix
        except Exception as e:
            log.error("account_folder_list_failed",
                      account_id=account.id,
                      error=e.message)
            error_message = ("Full IMAP support is not enabled for this account. "
                             "Please contact your domain "
                             "administrator and try again.")
            raise UserRecoverableConfigError(error_message)
        finally:
            conn.logout()

        # Verify SMTP login
        try:
            # Check that SMTP settings work by establishing and closing and
            # SMTP session.
            smtp_client = SMTPClient(account)
            with smtp_client._get_connection():
                pass
        except socket.gaierror as exc:
            log.error('Failed to resolve SMTP server domain',
                      account_id=account.id,
                      error=exc)
            error_message = ("Couldn't resolve the SMTP server domain name. "
                             "Please check that your SMTP settings are correct.")
            raise UserRecoverableConfigError(error_message)

        except socket.timeout as exc:
            log.error('TCP timeout when connecting to SMTP server',
                      account_id=account.id,
                      error=exc)

            error_message = ("Connection timeout when connecting to SMTP server. "
                             "Please check that your SMTP settings are correct.")
            raise UserRecoverableConfigError(error_message)

        except Exception as exc:
            log.error('Failed to establish an SMTP connection',
                      smtp_endpoint=account.smtp_endpoint,
                      account_id=account.id,
                      error=exc)
            raise UserRecoverableConfigError("Please check that your SMTP "
                                             "settings are correct.")

        # Reset the sync_state to 'running' on a successful re-auth.
        # Necessary for API requests to proceed and an account modify delta to
        # be returned to delta/ streaming clients.
        # NOTE: Setting this does not restart the sync. Sync scheduling occurs
        # via the sync_should_run bit (set to True in update_account() above).
        account.sync_state = ('running' if account.sync_state else
                              account.sync_state)
        return True