diff --git a/mailmerge/template_message.py b/mailmerge/template_message.py
index 135bba8..9a12fc4 100644
--- a/mailmerge/template_message.py
+++ b/mailmerge/template_message.py
@@ -115,9 +115,11 @@ class TemplateMessage(object):
 
         # Copy text, preserving original encoding
         original_text = self._message.get_payload(decode=True)
+        original_subtype = self._message.get_content_subtype()
         original_encoding = str(self._message.get_charset())
         multipart_message.attach(email.mime.text.MIMEText(
             original_text,
+            _subtype=original_subtype,
             _charset=original_encoding,
         ))
 

Content-Type gets overwritten to text/plain with attachment
Template:

```
From: a@example.invalic
TO: b@example.invalic
SUBJECT: Hello
ATTACHMENT: a.txt
CONTENT-TYPE: text/html

<html>
<body>
<p>Hi,</p>
</body>
</html>

```

command: `mailmerge --database database.csv --template 04.tpl  --output-format raw`

output:


```
>>> message 1
Content-Type: multipart/alternative;
 boundary="===============1872202902524908882=="
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
SUBJECT: Hello
From: a@example.invalic
TO: b@example.invalic
Date: Wed, 05 Aug 2020 21:37:21 -0000

--===============1872202902524908882==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

<html>
<body>
<p>Hi,</p>
</body>
</html>
--===============1872202902524908882==
Content-Type: application/octet-stream; Name="a.txt"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="a.txt"

aGVsbG93b3JsZA==

--===============1872202902524908882==--
>>> message 1 sent
>>> Limit was 1 message.  To remove the limit, use the --no-limit option.
>>> This was a dry run.  To send messages, use the --no-dry-run option.
```

The important part being `Content-Type: text/plain; charset="us-ascii"`, which is incorrect. Using a [html+plaintext](https://github.com/awdeorio/mailmerge#html-and-plain-text) message works, but that is more complicated.
diff --git a/tests/test_template_message.py b/tests/test_template_message.py
index 346975f..621a2bd 100644
--- a/tests/test_template_message.py
+++ b/tests/test_template_message.py
@@ -611,7 +611,7 @@ def test_attachment_multiple(tmp_path):
 
 
 def test_attachment_empty(tmp_path):
-    """Errr on empty attachment field."""
+    """Err on empty attachment field."""
     template_path = tmp_path / "template.txt"
     template_path.write_text(textwrap.dedent(u"""\
         TO: to@test.com
@@ -626,6 +626,75 @@ def test_attachment_empty(tmp_path):
         template_message.render({})
 
 
+def test_contenttype_attachment_html_body(tmpdir):
+    """
+    Verify that the content-type of the message is correctly retained with an
+    HTML body.
+    """
+    # Simple attachment
+    attachment_path = Path(tmpdir/"attachment.txt")
+    attachment_path.write_text(u"Hello world\n")
+
+    # HTML template
+    template_path = Path(tmpdir/"template.txt")
+    template_path.write_text(textwrap.dedent(u"""\
+        TO: to@test.com
+        FROM: from@test.com
+        ATTACHMENT: attachment.txt
+        CONTENT-TYPE: text/html
+
+        Hello world
+    """))
+
+    # Render in tmpdir
+    with tmpdir.as_cwd():
+        template_message = TemplateMessage(template_path)
+        _, _, message = template_message.render({})
+
+    # Verify that the message content type is HTML
+    payload = message.get_payload()
+    assert len(payload) == 2
+    assert payload[0].get_content_type() == 'text/html'
+
+
+def test_contenttype_attachment_markdown_body(tmpdir):
+    """
+    Verify that the content-types of the MarkDown message are correct when
+    attachments are included.
+    """
+    # Simple attachment
+    attachment_path = Path(tmpdir/"attachment.txt")
+    attachment_path.write_text(u"Hello world\n")
+
+    # HTML template
+    template_path = Path(tmpdir/"template.txt")
+    template_path.write_text(textwrap.dedent(u"""\
+        TO: to@test.com
+        FROM: from@test.com
+        ATTACHMENT: attachment.txt
+        CONTENT-TYPE: text/markdown
+
+        Hello **world**
+    """))
+
+    # Render in tmpdir
+    with tmpdir.as_cwd():
+        template_message = TemplateMessage(template_path)
+        _, _, message = template_message.render({})
+
+    # Markdown: Make sure there is a plaintext part and an HTML part
+    payload = message.get_payload()
+    assert len(payload) == 3
+
+    # Ensure that the first part is plaintext and the second part
+    # is HTML (as per RFC 2046)
+    plaintext_part = payload[0]
+    assert plaintext_part['Content-Type'].startswith("text/plain")
+
+    html_part = payload[1]
+    assert html_part['Content-Type'].startswith("text/html")
+
+
 def test_duplicate_headers_attachment(tmp_path):
     """Verify multipart messages do not contain duplicate headers.
 

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pycodestyle pydocstyle pylint check-manifest
apt-get update apt-get install -y gcc
3.9
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
astroid==3.3.9
attrs==25.3.0
backports.tarfile==1.2.0
build==1.2.2.post1
cachetools==5.5.2
certifi==2025.1.31
cffi==1.17.1
chardet==5.2.0
charset-normalizer==3.4.1
check-manifest==0.50
click==8.1.8
codecov==2.1.13
colorama==0.4.6
coverage==7.8.0
cryptography==44.0.2
dill==0.3.9
distlib==0.3.9
docutils==0.21.2
exceptiongroup==1.2.2
fancycompleter==0.9.1
filelock==3.18.0
future==1.0.0
id==1.5.0
idna==3.10
importlib_metadata==8.6.1
iniconfig==2.1.0
isort==6.0.1
jaraco.classes==3.4.0
jaraco.context==6.0.1
jaraco.functools==4.1.0
jeepney==0.9.0
Jinja2==3.1.6
keyring==25.6.0
-e git+https://github.com/awdeorio/mailmerge.git@d08667a8f2a7a9e7ad64e58c2bc049a80726bf3c#egg=mailmerge
Markdown==3.7
markdown-it-py==3.0.0
MarkupSafe==3.0.2
mccabe==0.7.0
mdurl==0.1.2
more-itertools==10.6.0
nh3==0.2.21
packaging==24.2
pdbpp==0.10.3
platformdirs==4.3.7
pluggy==1.5.0
pycodestyle==2.13.0
pycparser==2.22
pydocstyle==6.3.0
Pygments==2.19.1
pylint==3.3.6
pyproject-api==1.9.0
pyproject_hooks==1.2.0
pyrepl==0.9.0
pytest==8.3.5
pytest-cov==6.0.0
readme_renderer==44.0
requests==2.32.3
requests-toolbelt==1.0.0
rfc3986==2.0.0
rich==14.0.0
SecretStorage==3.3.3
sh==2.2.2
snowballstemmer==2.2.0
tomli==2.2.1
tomlkit==0.13.2
tox==4.25.0
twine==6.1.0
typing_extensions==4.13.0
urllib3==2.3.0
virtualenv==20.29.3
wmctrl==0.5
zipp==3.21.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
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - 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=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - astroid==3.3.9
      - attrs==25.3.0
      - backports-tarfile==1.2.0
      - build==1.2.2.post1
      - cachetools==5.5.2
      - certifi==2025.1.31
      - cffi==1.17.1
      - chardet==5.2.0
      - charset-normalizer==3.4.1
      - check-manifest==0.50
      - click==8.1.8
      - codecov==2.1.13
      - colorama==0.4.6
      - coverage==7.8.0
      - cryptography==44.0.2
      - dill==0.3.9
      - distlib==0.3.9
      - docutils==0.21.2
      - exceptiongroup==1.2.2
      - fancycompleter==0.9.1
      - filelock==3.18.0
      - future==1.0.0
      - id==1.5.0
      - idna==3.10
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - isort==6.0.1
      - jaraco-classes==3.4.0
      - jaraco-context==6.0.1
      - jaraco-functools==4.1.0
      - jeepney==0.9.0
      - jinja2==3.1.6
      - keyring==25.6.0
      - markdown==3.7
      - markdown-it-py==3.0.0
      - markupsafe==3.0.2
      - mccabe==0.7.0
      - mdurl==0.1.2
      - more-itertools==10.6.0
      - nh3==0.2.21
      - packaging==24.2
      - pdbpp==0.10.3
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pycodestyle==2.13.0
      - pycparser==2.22
      - pydocstyle==6.3.0
      - pygments==2.19.1
      - pylint==3.3.6
      - pyproject-api==1.9.0
      - pyproject-hooks==1.2.0
      - pyrepl==0.9.0
      - pytest==8.3.5
      - pytest-cov==6.0.0
      - readme-renderer==44.0
      - requests==2.32.3
      - requests-toolbelt==1.0.0
      - rfc3986==2.0.0
      - rich==14.0.0
      - secretstorage==3.3.3
      - sh==2.2.2
      - snowballstemmer==2.2.0
      - tomli==2.2.1
      - tomlkit==0.13.2
      - tox==4.25.0
      - twine==6.1.0
      - typing-extensions==4.13.0
      - urllib3==2.3.0
      - virtualenv==20.29.3
      - wmctrl==0.5
      - zipp==3.21.0
prefix: /opt/conda/envs/mailmerge

tests/test_template_message.py::test_contenttype_attachment_html_body
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 tests/test_template_message.py::test_contenttype_attachment_markdown_body tests/test_template_message.py::test_duplicate_headers_attachment tests/test_template_message.py::test_duplicate_headers_markdown
mailmerge/template_message.py
mailmerge/template_message.py