---
Product: Aspose.Email
Platform: python
Page Type: reference
Canonical URL: https://reference.aspose.org/email/python/msgwriter
---

# MsgWriter

## Overview

`MsgWriter` is a class in Aspose.Email FOSS for Python.

Serializer that writes a MsgDocument into a CFB-backed .msg payload.

This class provides 2 methods for working with MsgWriter objects in Python programs.
Available methods include: `to_bytes`, `write_file`.
All public members are accessible to any Python application after installing the Aspose.Email FOSS for Python package.

## Methods

| Signature | Description |
|-----------|-------------|
| `to_bytes(document: MsgDocument)` → `bytes` | Serializes a MsgDocument into a bytes object representing an Outlook .msg file |
| `write_file(document: MsgDocument, path: Path \| str)` | Writes a MsgDocument to the given filesystem path as an Outlook .msg file |

## Examples

```python
from aspose.email_foss.msg import MsgDocument, MsgWriter

doc = MsgDocument.from_file("input.msg")
MsgWriter.write_file(doc, "output.msg")
data = MsgWriter.to_bytes(doc)
```

## See Also

- [Aspose.Email for Python — Enterprise API Reference](https://reference.aspose.com/email/python-net/)