def connect(site, get_server, debug=False):
    """connect to the mail server"""
    if site.smtp_host and site.smtp_port:
        server = get_server(site.smtp_host, site.smtp_port)
        if debug:
            server.set_debuglevel(1)
        if site.smtp_user and site.smtp_passwd:
            server.login(site.smtp_user, site.smtp_passwd)
        return server
