How to use mailmerge - 10 common examples

To help you get started, we’ve selected a few mailmerge examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Bouke / docx-mailmerge / tests / test_issue8.py View on Github external
def test(self):
        with MailMerge(path.join(path.dirname(__file__), 'test_issue8.docx')) as document:
            self.assertEqual(document.get_merge_fields(), {'testfield'})
github Bouke / docx-mailmerge / tests / test_winword2010.py View on Github external
def test(self):
        with MailMerge(path.join(path.dirname(__file__), 'test_winword2010.docx')) as document:
            self.assertEqual(document.get_merge_fields(),
                             set(['Titel', 'Voornaam', 'Achternaam',
                                  'Adresregel_1', 'Postcode', 'Plaats',
                                  'Provincie', 'Land_of_regio']))

            document.merge(Voornaam='Bouke', Achternaam='Haarsma',
                           Land_of_regio='The Netherlands', Provincie=None,
                           Postcode='9723 ZA', Plaats='Groningen',
                           Adresregel_1='Helperpark 278d\nP.O. Box', Titel='dhr.')

            with tempfile.NamedTemporaryFile() as outfile:
                document.write(outfile)

        expected_tree = etree.fromstring(
            ''  # noqa
              ''
github Bouke / docx-mailmerge / tests / test_macword2011.py View on Github external
def test(self):
        with MailMerge(path.join(path.dirname(__file__), 'test_macword2011.docx')) as document:
            self.assertEqual(document.get_merge_fields(),
                             set(['first_name', 'last_name', 'country', 'state',
                                  'postal_code', 'date', 'address_line', 'city']))

            document.merge(first_name='Bouke', last_name='Haarsma',
                           country='The Netherlands', state=None,
                           postal_code='9723 ZA', city='Groningen',
                           address_line='Helperpark 278d', date='May 22nd, 2013')

            with tempfile.TemporaryFile() as outfile:
                document.write(outfile)

        expected_tree = etree.fromstring(
            ''
github awdeorio / mailmerge / tests / test_simple.py View on Github external
def test(self):
        """A basic test using the default options"""
        # pylint: disable=no-self-use

        # Run executable on sample input files
        mailmerge.api.main(
            database_filename="test_simple.database.csv",
            template_filename="test_simple.template.txt",
            config_filename="server_dummy.conf",
            dry_run=True,
            no_limit=True,
        )
github awdeorio / mailmerge / tests / test_helpers.py View on Github external
def test_enumerate_limit_no_limit():
    """Verify limit=-1 results in no early termination."""
    iterations = 0
    for _, _ in mailmerge.__main__.enumerate_limit(["a", "b", "c"], -1):
        iterations += 1
    assert iterations == 3
github awdeorio / mailmerge / tests / test_helpers.py View on Github external
def test_enumerate_limit_values():
    """Verify limit=-1 results in no early termination."""
    values = ["a", "b", "c"]
    for i, value in mailmerge.__main__.enumerate_limit(values, -1):
        assert value == values[i]
github awdeorio / mailmerge / tests / test_helpers.py View on Github external
def test_enumerate_limit_zero():
    """Verify limit results in early termination."""
    iterations = 0
    for _, _ in mailmerge.__main__.enumerate_limit(["a", "b", "c"], 0):
        iterations += 1
    assert iterations == 0
github awdeorio / mailmerge / tests / test_helpers.py View on Github external
def test_enumerate_limit_stop_early():
    """Verify limit results in early termination."""
    iterations = 0
    for _, _ in mailmerge.__main__.enumerate_limit(["a", "b", "c"], 2):
        iterations += 1
    assert iterations == 2
github awdeorio / mailmerge / tests / test_template_message.py View on Github external
--boundary
        Content-Type: text/plain; charset=utf-8

        Hello Laȝamon

        --boundary
        Content-Type: text/html; charset=utf-8

        
          
            <p>Hello Laȝamon</p>
          
        
    """))
    template_message = TemplateMessage(template_path)
    sender, recipients, message = template_message.render({})

    # Verify sender and recipients
    assert sender == "from@test.com"
    assert recipients == ["to@test.com"]

    # Should be multipart: plaintext and HTML
    assert message.is_multipart()
    parts = message.get_payload()
    assert len(parts) == 2
    plaintext_part, html_part = parts

    # Verify plaintext part
    assert plaintext_part.get_charset() == "utf-8"
    assert plaintext_part.get_content_charset() == "utf-8"
    assert plaintext_part.get_content_type() == "text/plain"
github awdeorio / mailmerge / tests / test_template_message.py View on Github external
def test_simple(tmp_path):
    """Render a simple template."""
    template_path = tmp_path / "template.txt"
    template_path.write_text(textwrap.dedent(u"""\
        TO: to@test.com
        SUBJECT: Testing mailmerge
        FROM: from@test.com

        Hello {{name}}!
    """))
    template_message = TemplateMessage(template_path)
    sender, recipients, message = template_message.render({
        "name": "world",
    })
    assert sender == "from@test.com"
    assert recipients == ["to@test.com"]
    plaintext = message.get_payload()
    assert "Hello world!" in plaintext