예제 #1
0
 def test__func__connect_disconnect__ok__nominal_case(self, app_config, mailhog):
     smtp_config = SmtpConfiguration(
         app_config.EMAIL__NOTIFICATION__SMTP__SERVER,
         app_config.EMAIL__NOTIFICATION__SMTP__PORT,
         app_config.EMAIL__NOTIFICATION__SMTP__USER,
         app_config.EMAIL__NOTIFICATION__SMTP__PASSWORD,
         app_config.EMAIL__NOTIFICATION__SMTP__USE_IMPLICIT_SSL,
     )
     sender = EmailSender(app_config, smtp_config, True)
     sender.connect()
     sender.disconnect()
예제 #2
0
    def _get_email_manager(self, config: CFG, session: Session) -> ShareEmailManager:
        """
        :return: EmailManager instance
        """
        smtp_config = SmtpConfiguration(
            config.EMAIL__NOTIFICATION__SMTP__SERVER,
            config.EMAIL__NOTIFICATION__SMTP__PORT,
            config.EMAIL__NOTIFICATION__SMTP__USER,
            config.EMAIL__NOTIFICATION__SMTP__PASSWORD,
            config.EMAIL__NOTIFICATION__SMTP__USE_IMPLICIT_SSL,
        )

        return ShareEmailManager(config=config, smtp_config=smtp_config, session=session)
예제 #3
0
 def test__func__connect_disconnect__ok__nominal_case(self):
     smtp_config = SmtpConfiguration(
         self.app_config.EMAIL_NOTIFICATION_SMTP_SERVER,
         self.app_config.EMAIL_NOTIFICATION_SMTP_PORT,
         self.app_config.EMAIL_NOTIFICATION_SMTP_USER,
         self.app_config.EMAIL_NOTIFICATION_SMTP_PASSWORD)
     sender = EmailSender(
         self.app_config,
         smtp_config,
         True,
     )
     sender.connect()
     sender.disconnect()
예제 #4
0
파일: notifier.py 프로젝트: buxx/tracim
def get_email_manager(config: CFG, session: Session):
    """
    :return: EmailManager instance
    """
    #  TODO: Find a way to import properly without cyclic import

    smtp_config = SmtpConfiguration(
        config.EMAIL_NOTIFICATION_SMTP_SERVER,
        config.EMAIL_NOTIFICATION_SMTP_PORT,
        config.EMAIL_NOTIFICATION_SMTP_USER,
        config.EMAIL_NOTIFICATION_SMTP_PASSWORD
    )

    return EmailManager(config=config, smtp_config=smtp_config, session=session)
예제 #5
0
    def test__func__send_email_notification__ok__nominal_case(self, app_config, mailhog):
        smtp_config = SmtpConfiguration(
            app_config.EMAIL__NOTIFICATION__SMTP__SERVER,
            app_config.EMAIL__NOTIFICATION__SMTP__PORT,
            app_config.EMAIL__NOTIFICATION__SMTP__USER,
            app_config.EMAIL__NOTIFICATION__SMTP__PASSWORD,
            app_config.EMAIL__NOTIFICATION__SMTP__USE_IMPLICIT_SSL,
        )
        sender = EmailSender(app_config, smtp_config, True)
        html = """\
        <html>
          <head></head>
          <body>
            <p>test__func__send_email__ok__nominal_case</p>
          </body>
        </html>
        """.replace(
            " ", ""
        ).replace(
            "\n", ""
        )
        msg = EmailNotificationMessage(
            subject="test__func__send_email__ok__nominal_case",
            from_header=EmailAddress("", "test_send_mail@localhost"),
            to_header=EmailAddress("", "receiver_test_send_mail@localhost"),
            reply_to=EmailAddress("", "replyto@localhost"),
            references=EmailAddress("", "references@localhost"),
            lang="en",
            body_html=html,
        )
        sender.send_mail(msg)
        sender.disconnect()

        # check mail received
        response = mailhog.get_mailhog_mails()
        headers = response[0]["Content"]["Headers"]
        assert headers["From"][0] == "test_send_mail@localhost"
        assert headers["To"][0] == "receiver_test_send_mail@localhost"
        assert headers["Subject"][0] == "test__func__send_email__ok__nominal_case"
        assert headers["Content-Language"][0] == "en"
        assert headers["Message-ID"]
        assert headers["Date"]
        assert headers["Reply-to"][0] == "replyto@localhost"
        assert headers["References"][0] == "references@localhost"
        assert headers["X-Auto-Response-Suppress"][0] == "All"
        assert headers["Auto-Submitted"][0] == "auto-generated"
        assert response[0]["MIME"]["Parts"][0]["Body"]
        assert response[0]["MIME"]["Parts"][1]["Body"]
예제 #6
0
    def __init__(self, config: CFG, session: Session, current_user: User = None):
        """
        :param current_user: the user that has triggered the notification
        :return:
        """
        INotifier.__init__(self, config, session, current_user)
        logger.info(self, "Instantiating Email Notifier")

        self._user = current_user
        self.session = session
        self.config = config
        self._smtp_config = SmtpConfiguration(
            self.config.EMAIL__NOTIFICATION__SMTP__SERVER,
            self.config.EMAIL__NOTIFICATION__SMTP__PORT,
            self.config.EMAIL__NOTIFICATION__SMTP__USER,
            self.config.EMAIL__NOTIFICATION__SMTP__PASSWORD,
        )
예제 #7
0
    def test__func__send_email__ok__nominal_case(self, app_config, mailhog):
        smtp_config = SmtpConfiguration(
            app_config.EMAIL__NOTIFICATION__SMTP__SERVER,
            app_config.EMAIL__NOTIFICATION__SMTP__PORT,
            app_config.EMAIL__NOTIFICATION__SMTP__USER,
            app_config.EMAIL__NOTIFICATION__SMTP__PASSWORD,
            app_config.EMAIL__NOTIFICATION__SMTP__USE_IMPLICIT_SSL,
        )
        sender = EmailSender(app_config, smtp_config, True)

        # Create test_mail
        msg = MIMEMultipart()
        msg["Subject"] = "test__func__send_email__ok__nominal_case"
        msg["From"] = "test_send_mail@localhost"
        msg["To"] = "receiver_test_send_mail@localhost"
        text = "test__func__send_email__ok__nominal_case"
        html = """\
        <html>
          <head></head>
          <body>
            <p>test__func__send_email__ok__nominal_case</p>
          </body>
        </html>
        """.replace(
            " ", ""
        ).replace(
            "\n", ""
        )
        part1 = MIMEText(text, "plain")
        part2 = MIMEText(html, "html")
        msg.attach(part1)
        msg.attach(part2)

        sender.send_mail(msg)
        sender.disconnect()

        # check mail received
        response = mailhog.get_mailhog_mails()
        headers = response[0]["Content"]["Headers"]
        assert headers["From"][0] == "test_send_mail@localhost"
        assert headers["To"][0] == "receiver_test_send_mail@localhost"
        assert headers["Subject"][0] == "test__func__send_email__ok__nominal_case"
        assert response[0]["MIME"]["Parts"][0]["Body"] == text
        assert response[0]["MIME"]["Parts"][1]["Body"] == html
예제 #8
0
    def test__func__send_email__ok__nominal_case(self):
        smtp_config = SmtpConfiguration(
            self.app_config.EMAIL_NOTIFICATION_SMTP_SERVER,
            self.app_config.EMAIL_NOTIFICATION_SMTP_PORT,
            self.app_config.EMAIL_NOTIFICATION_SMTP_USER,
            self.app_config.EMAIL_NOTIFICATION_SMTP_PASSWORD)
        sender = EmailSender(
            self.app_config,
            smtp_config,
            True,
        )

        # Create test_mail
        msg = MIMEMultipart()
        msg['Subject'] = 'test__func__send_email__ok__nominal_case'
        msg['From'] = 'test_send_mail@localhost'
        msg['To'] = 'receiver_test_send_mail@localhost'
        text = "test__func__send_email__ok__nominal_case"
        html = """\
        <html>
          <head></head>
          <body>
            <p>test__func__send_email__ok__nominal_case</p>
          </body>
        </html>
        """.replace(' ', '').replace('\n', '')
        part1 = MIMEText(text, 'plain')
        part2 = MIMEText(html, 'html')
        msg.attach(part1)
        msg.attach(part2)

        sender.send_mail(msg)
        sender.disconnect()

        # check mail received
        response = requests.get('http://127.0.0.1:8025/api/v1/messages')
        response = response.json()
        headers = response[0]['Content']['Headers']
        assert headers['From'][0] == 'test_send_mail@localhost'
        assert headers['To'][0] == 'receiver_test_send_mail@localhost'
        assert headers['Subject'][
            0] == 'test__func__send_email__ok__nominal_case'  # nopep8
        assert response[0]['MIME']['Parts'][0]['Body'] == text
        assert response[0]['MIME']['Parts'][1]['Body'] == html