diff --git a/mailmerge/template_message.py b/mailmerge/template_message.py
index c90c505..135bba8 100644
--- a/mailmerge/template_message.py
+++ b/mailmerge/template_message.py
@@ -102,8 +102,13 @@ class TemplateMessage(object):
         # Create empty multipart message
         multipart_message = email.mime.multipart.MIMEMultipart('alternative')
 
-        # Copy headers, preserving duplicate headers
+        # Copy headers.  Avoid duplicate Content-Type and MIME-Version headers,
+        # which we set explicitely.  MIME-Version was set when we created an
+        # empty mulitpart message.  Content-Type will be set when we copy the
+        # original text later.
         for header_key in set(self._message.keys()):
+            if header_key.lower() in ["content-type", "mime-version"]:
+                continue
             values = self._message.get_all(header_key, failobj=[])
             for value in values:
                 multipart_message[header_key] = value

With attachments its send duplicate header of Content Type
This is the email header with attachment . Without attachment is okay

> Content-Type: multipart/alternative; boundary="===============6399458286909476=="
> MIME-Version: 1.0
> Content-Type: multipart/alternative; boundary="===============6399458286909476=="
> SUBJECT: Testing mailmerge
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> FROM: User <email@email.com>
> TO: noreply@user.com
> Date: Mon, 18 May 2020 18:21:03 -0000
diff --git a/tests/test_template_message.py b/tests/test_template_message.py
index 18e0d5d..346975f 100644
--- a/tests/test_template_message.py
+++ b/tests/test_template_message.py
@@ -624,3 +624,56 @@ def test_attachment_empty(tmp_path):
     template_message = TemplateMessage(template_path)
     with pytest.raises(MailmergeError):
         template_message.render({})
+
+
+def test_duplicate_headers_attachment(tmp_path):
+    """Verify multipart messages do not contain duplicate headers.
+
+    Duplicate headers are rejected by some SMTP servers.
+    """
+    # Simple attachment
+    attachment_path = Path(tmp_path/"attachment.txt")
+    attachment_path.write_text(u"Hello world\n")
+
+    # Simple message
+    template_path = tmp_path / "template.txt"
+    template_path.write_text(textwrap.dedent(u"""\
+        TO: to@test.com
+        SUBJECT: Testing mailmerge
+        FROM: from@test.com>
+        ATTACHMENT: attachment.txt
+
+        {{message}}
+    """))
+    template_message = TemplateMessage(template_path)
+    _, _, message = template_message.render({
+        "message": "Hello world"
+    })
+
+    # Verifty no duplicate headers
+    assert len(message.keys()) == len(set(message.keys()))
+
+
+def test_duplicate_headers_markdown(tmp_path):
+    """Verify multipart messages do not contain duplicate headers.
+
+    Duplicate headers are rejected by some SMTP servers.
+    """
+    template_path = tmp_path / "template.txt"
+    template_path.write_text(textwrap.dedent(u"""\
+        TO: to@test.com
+        SUBJECT: Testing mailmerge
+        FROM: from@test.com
+        CONTENT-TYPE: text/markdown
+
+        ```
+        Message as code block: {{message}}
+        ```
+    """))
+    template_message = TemplateMessage(template_path)
+    _, _, message = template_message.render({
+        "message": "hello world",
+    })
+
+    # Verifty no duplicate headers
+    assert len(message.keys()) == len(set(message.keys()))

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-xdist pytest-mock pytest-asyncio
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
astroid==2.11.7
attrs==22.2.0
bleach==4.1.0
build==0.9.0
certifi==2021.5.30
cffi==1.15.1
charset-normalizer==2.0.12
check-manifest==0.48
click==8.0.4
codecov==2.1.13
colorama==0.4.5
coverage==6.2
cryptography==40.0.2
dill==0.3.4
distlib==0.3.9
docutils==0.18.1
execnet==1.9.0
fancycompleter==0.9.1
filelock==3.4.1
future==1.0.0
idna==3.10
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig==1.1.1
isort==5.10.1
jeepney==0.7.1
Jinja2==3.0.3
keyring==23.4.1
lazy-object-proxy==1.7.1
-e git+https://github.com/awdeorio/mailmerge.git@a95c4951e91edac5c7bfa5e19f2389c7e4657d47#egg=mailmerge
Markdown==3.3.7
MarkupSafe==2.0.1
mccabe==0.7.0
packaging==21.3
pdbpp==0.10.3
pep517==0.13.1
pkginfo==1.10.0
platformdirs==2.4.0
pluggy==1.0.0
py==1.11.0
pycodestyle==2.10.0
pycparser==2.21
pydocstyle==6.3.0
Pygments==2.14.0
pylint==2.13.9
pyparsing==3.1.4
pyrepl==0.9.0
pytest==7.0.1
pytest-asyncio==0.16.0
pytest-cov==4.0.0
pytest-mock==3.6.1
pytest-xdist==3.0.2
readme-renderer==34.0
requests==2.27.1
requests-toolbelt==1.0.0
rfc3986==1.5.0
SecretStorage==3.3.3
sh==1.14.3
six==1.17.0
snowballstemmer==2.2.0
toml==0.10.2
tomli==1.2.3
tox==3.28.0
tqdm==4.64.1
twine==3.8.0
typed-ast==1.5.5
typing_extensions==4.1.1
urllib3==1.26.20
virtualenv==20.17.1
webencodings==0.5.1
wmctrl==0.5
wrapt==1.16.0
zipp==3.6.0

name: mailmerge
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - astroid==2.11.7
      - attrs==22.2.0
      - bleach==4.1.0
      - build==0.9.0
      - cffi==1.15.1
      - charset-normalizer==2.0.12
      - check-manifest==0.48
      - click==8.0.4
      - codecov==2.1.13
      - colorama==0.4.5
      - coverage==6.2
      - cryptography==40.0.2
      - dill==0.3.4
      - distlib==0.3.9
      - docutils==0.18.1
      - execnet==1.9.0
      - fancycompleter==0.9.1
      - filelock==3.4.1
      - future==1.0.0
      - idna==3.10
      - importlib-metadata==4.8.3
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - isort==5.10.1
      - jeepney==0.7.1
      - jinja2==3.0.3
      - keyring==23.4.1
      - lazy-object-proxy==1.7.1
      - markdown==3.3.7
      - markupsafe==2.0.1
      - mccabe==0.7.0
      - packaging==21.3
      - pdbpp==0.10.3
      - pep517==0.13.1
      - pkginfo==1.10.0
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - py==1.11.0
      - pycodestyle==2.10.0
      - pycparser==2.21
      - pydocstyle==6.3.0
      - pygments==2.14.0
      - pylint==2.13.9
      - pyparsing==3.1.4
      - pyrepl==0.9.0
      - pytest==7.0.1
      - pytest-asyncio==0.16.0
      - pytest-cov==4.0.0
      - pytest-mock==3.6.1
      - pytest-xdist==3.0.2
      - readme-renderer==34.0
      - requests==2.27.1
      - requests-toolbelt==1.0.0
      - rfc3986==1.5.0
      - secretstorage==3.3.3
      - sh==1.14.3
      - six==1.17.0
      - snowballstemmer==2.2.0
      - toml==0.10.2
      - tomli==1.2.3
      - tox==3.28.0
      - tqdm==4.64.1
      - twine==3.8.0
      - typed-ast==1.5.5
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - virtualenv==20.17.1
      - webencodings==0.5.1
      - wmctrl==0.5
      - wrapt==1.16.0
      - zipp==3.6.0
prefix: /opt/conda/envs/mailmerge

tests/test_template_message.py::test_duplicate_headers_attachment tests/test_template_message.py::test_duplicate_headers_markdown
tests/test_template_message.py::test_simple tests/test_template_message.py::test_no_substitutions tests/test_template_message.py::test_multiple_substitutions tests/test_template_message.py::test_bad_jinja tests/test_template_message.py::test_cc_bcc tests/test_template_message.py::test_html tests/test_template_message.py::test_html_plaintext tests/test_template_message.py::test_markdown tests/test_template_message.py::test_markdown_encoding tests/test_template_message.py::test_attachment_simple tests/test_template_message.py::test_attachment_relative tests/test_template_message.py::test_attachment_absolute tests/test_template_message.py::test_attachment_template tests/test_template_message.py::test_attachment_not_found tests/test_template_message.py::test_attachment_blank tests/test_template_message.py::test_attachment_tilde_path tests/test_template_message.py::test_attachment_multiple tests/test_template_message.py::test_attachment_empty
mailmerge/template_message.py
mailmerge/template_message.py