'Close the connection to the email server.'

def close(self):

    if (self.connection is None):
        return
    try:
        self.connection.quit()
    except (ssl.SSLError, smtplib.SMTPServerDisconnected):
        self.connection.close()
    except smtplib.SMTPException:
        if self.fail_silently:
            return
        raise
    finally:
        self.connection = None
