Esempio n. 1
0
def test_can_receive_emails_and_extract_content():
    with mailslurp_client.ApiClient(configuration) as api_client:
        # create two inboxes for testing
        inbox_controller = mailslurp_client.InboxControllerApi(api_client)
        inbox_1 = inbox_controller.create_inbox()
        inbox_2 = inbox_controller.create_inbox()

        # send email from inbox 1 to inbox 2
        send_email_options = mailslurp_client.SendEmailOptions()
        send_email_options.to = [inbox_2.email_address]
        send_email_options.subject = "Hello inbox 2"
        send_email_options.body = "Your code is: 123"
        inbox_controller.send_email(inbox_1.id,
                                    send_email_options=send_email_options)

        # receive email for inbox 2
        waitfor_controller = mailslurp_client.WaitForControllerApi(api_client)
        email = waitfor_controller.wait_for_latest_email(inbox_id=inbox_2.id,
                                                         timeout=30000,
                                                         unread_only=True)

        assert email.subject == "Hello inbox 2"

        # extract content from body
        pattern = re.compile('Your code is: ([0-9]{3})')
        matches = pattern.match(email.body)
        code = matches.group(1)

        assert code == "123"
Esempio n. 2
0
 def wait_for_latest_email(self, inbox_id):
     with mailslurp_client.ApiClient(self.configuration) as api_client:
         # create an inbox using the inbox controller
         api_instance = mailslurp_client.WaitForControllerApi(api_client)
         email = api_instance.wait_for_latest_email(inbox_id=inbox_id,
                                                    timeout=60000,
                                                    unread_only=True)
         return email
Esempio n. 3
0
def test_can_create_email_address():
    with mailslurp_client.ApiClient(configuration) as api_client:
        # create an inbox using the inbox controller
        api_instance = mailslurp_client.InboxControllerApi(api_client)
        inbox = api_instance.create_inbox()

        # check the id and email_address of the inbox
        assert len(inbox.id) > 0
        assert "mailslurp.com" in inbox.email_address
Esempio n. 4
0
def create_email():  # Create a temporary email using the mailslurp api
    print('Creating Email')  # Identifier
    with mailslurp_client.ApiClient(configuration) as api_client:
        # create an inbox using the inbox controller
        api_instance = mailslurp_client.InboxControllerApi(api_client)
        inbox = api_instance.create_inbox()

        # check the id and email_address of the inbox
        assert len(inbox.id) > 0
        assert "mailslurp.com" in inbox.email_address
        return inbox, inbox.email_address
Esempio n. 5
0
def get_email_content_from_mailslurp(email_id, configuration):
    with mailslurp_client.ApiClient(configuration) as api_client:
        api_instance = mailslurp_client.EmailControllerApi(api_client)
        decode = False
        api_response = None
        try:
            api_response = api_instance.get_email_html(email_id, decode=decode)
            return api_response
        except ApiException as e:
            logging.error(
                "Exception when calling EmailControllerApi->get_email_html: %s\n"
                % e)
            raise ValueError(
                "Unable to retrieve email content with emailId = " + email_id)
Esempio n. 6
0
def test_can_send_email():
    with mailslurp_client.ApiClient(configuration) as api_client:
        # first create an inbox
        api_instance = mailslurp_client.InboxControllerApi(api_client)
        inbox = api_instance.create_inbox()

        # send email from the inbox
        send_email_options = mailslurp_client.SendEmailOptions()
        send_email_options.to = [inbox.email_address]
        send_email_options.subject = "Hello"
        send_email_options.body = """
        <h1>MailSlurp supports HTML</h1>
        """
        send_email_options.is_html = True
        api_instance.send_email(inbox.id,
                                send_email_options=send_email_options)
Esempio n. 7
0
def verify(inbox):
    print("Verifying Email")
    with mailslurp_client.ApiClient(configuration) as api_client:
        # Find the inbox
        inbox_1 = inbox

        # receive email for inbox 1
        waitfor_controller = mailslurp_client.WaitForControllerApi(api_client)
        email = waitfor_controller.wait_for_latest_email(inbox_id=inbox_1.id,
                                                         timeout=30000,
                                                         unread_only=True)

        assert email.subject == "Welcome to the DCP Network!"

        html = email.body
        match = slicer("Your verification code is: ", "<", html)

        return match
Esempio n. 8
0
 def create_inbox(self):
     with mailslurp_client.ApiClient(self.configuration) as api_client:
         # create an inbox using the inbox controller
         api_instance = mailslurp_client.InboxControllerApi(api_client)
         inbox = api_instance.create_inbox()
         return inbox
Esempio n. 9
0
 def __init__(self):
     self.configuration = mailslurp_client.Configuration()
     self.configuration.api_key['x-api-key'] = mailSlurpApiKey
     self.configuration.host = "https://api.mailslurp.com"
     self.client = mailslurp_client.ApiClient(self.configuration)