diff --git a/gmailconnector/__init__.py b/gmailconnector/__init__.py index 93989b4..ddcc429 100644 --- a/gmailconnector/__init__.py +++ b/gmailconnector/__init__.py @@ -12,9 +12,10 @@ from .send_email import SendEmail # noqa: F401 from .send_sms import SendSMS # noqa: F401 from .sms_deleter import DeleteSent # noqa: F401 +from .validator.address import EmailAddress # noqa: F401 from .validator.validate_email import validate_email # noqa: F401 -version = "0.7" +version = "0.8" def load_env(filename: Union[str, os.PathLike] = ".env", scan: bool = False) -> NoReturn: diff --git a/gmailconnector/send_email.py b/gmailconnector/send_email.py index c7a0722..6509d38 100644 --- a/gmailconnector/send_email.py +++ b/gmailconnector/send_email.py @@ -8,6 +8,7 @@ from .models.config import Encryption from .models.responder import Response +from .validator.address import EmailAddress class SendEmail: @@ -198,6 +199,7 @@ def send_email(self, subject: str, recipient: Union[str, list] = None, raise ValueError( 'Cannot proceed without the arg: `recipient`' ) + recipient = EmailAddress(address=recipient).email # validates recipient before sending email if not self._authenticated: status = self.authenticate if not status.ok: diff --git a/release_notes.rst b/release_notes.rst index 357ef54..c996dce 100644 --- a/release_notes.rst +++ b/release_notes.rst @@ -1,6 +1,12 @@ Release Notes ============= +0.7.9 (04/03/2023) +------------------ +- Validate recipient address format in send_email.py +- Make validator available on name space package +- Update test runner + 0.7.8 (04/03/2023) ------------------ - Update README.md and python version requirement diff --git a/test_runner.py b/test_runner.py index cc59578..744b249 100644 --- a/test_runner.py +++ b/test_runner.py @@ -5,11 +5,15 @@ import gmailconnector as gc logger = logging.getLogger(__name__) +handler = logging.StreamHandler() +handler.setFormatter(logging.Formatter('%(asctime)s - [%(module)s:%(lineno)d] - %(funcName)s - %(message)s')) +logger.addHandler(handler) logger.setLevel(logging.INFO) -logger.addHandler(logging.StreamHandler()) gc.load_env(filename="secrets.env") +logger.info("RUNNING TESTS on version: %s", gc.version) + def test_run_read_email(): """Test run read emails.""" @@ -77,7 +81,7 @@ def test_run_send_sms_ssl(): def test_run_validate_email_smtp_off(): """Test run on email validator with SMTP disabled.""" - logger.info("Test initiated on email validator using SMTP enabled.") + logger.info("Test initiated on email validator with SMTP disabled.") response = gc.validate_email(email_address=os.environ.get("GMAIL_USER"), smtp_check=False, debug=True, logger=logger) assert response.ok, response.body @@ -86,7 +90,7 @@ def test_run_validate_email_smtp_off(): def test_run_validate_email_smtp_on(): """Test run on email validator with SMTP enabled.""" - logger.info("Test initiated on email validator using SMTP disabled.") + logger.info("Test initiated on email validator with SMTP enabled.") response = gc.validate_email(email_address=os.environ.get("GMAIL_USER"), smtp_check=True, debug=True, logger=logger) assert response.status <= 299, response.body @@ -94,10 +98,10 @@ def test_run_validate_email_smtp_on(): if __name__ == '__main__': - # test_run_validate_email_smtp_off() - # test_run_validate_email_smtp_on() - # test_run_send_email_tls() - # test_run_send_email_ssl() + test_run_validate_email_smtp_off() + test_run_validate_email_smtp_on() + test_run_send_email_tls() + test_run_send_email_ssl() test_run_send_sms_tls() test_run_send_sms_ssl() - # test_run_read_email() + test_run_read_email()