---
title: Email
---

이 노트북은 email (`.eml`) 또는 `Microsoft Outlook` (`.msg`) 파일을 로드하는 방법을 보여줍니다.

Unstructured를 로컬에서 설정하는 방법에 대한 자세한 내용은 [이 가이드](/oss/python/integrations/providers/unstructured/)를 참조하세요. 필요한 시스템 종속성 설정도 포함되어 있습니다.

## Unstructured 사용하기

```python
pip install -qU unstructured
from langchain_community.document_loaders import UnstructuredEmailLoader

loader = UnstructuredEmailLoader("./example_data/fake-email.eml")

data = loader.load()

data
[Document(page_content='This is a test email to use for unit tests.\n\nImportant points:\n\nRoses are red\n\nViolets are blue', metadata={'source': './example_data/fake-email.eml'})]

Element 유지하기

내부적으로 Unstructured는 텍스트의 다양한 청크에 대해 서로 다른 “element”를 생성합니다. 기본적으로 이들을 결합하지만, mode="elements"를 지정하여 분리된 상태를 쉽게 유지할 수 있습니다.
loader = UnstructuredEmailLoader("example_data/fake-email.eml", mode="elements")

data = loader.load()

data[0]
Document(page_content='This is a test email to use for unit tests.', metadata={'source': 'example_data/fake-email.eml', 'file_directory': 'example_data', 'filename': 'fake-email.eml', 'last_modified': '2022-12-16T17:04:16-05:00', 'sent_from': ['Matthew Robinson [[email protected]](mailto:[email protected])'], 'sent_to': ['Matthew Robinson [[email protected]](mailto:[email protected])'], 'subject': 'Test Email', 'languages': ['eng'], 'filetype': 'message/rfc822', 'category': 'NarrativeText'})

첨부 파일 처리하기

UnstructuredEmailLoader의 생성자에서 process_attachments=True를 설정하여 첨부 파일을 처리할 수 있습니다. 기본적으로 첨부 파일은 unstructuredpartition 함수를 사용하여 분할됩니다. attachment_partitioner kwarg에 함수를 전달하여 다른 분할 함수를 사용할 수 있습니다.
loader = UnstructuredEmailLoader(
    "example_data/fake-email.eml",
    mode="elements",
    process_attachments=True,
)

data = loader.load()

data[0]
Document(page_content='This is a test email to use for unit tests.', metadata={'source': 'example_data/fake-email.eml', 'file_directory': 'example_data', 'filename': 'fake-email.eml', 'last_modified': '2022-12-16T17:04:16-05:00', 'sent_from': ['Matthew Robinson [[email protected]](mailto:[email protected])'], 'sent_to': ['Matthew Robinson [[email protected]](mailto:[email protected])'], 'subject': 'Test Email', 'languages': ['eng'], 'filetype': 'message/rfc822', 'category': 'NarrativeText'})

OutlookMessageLoader 사용하기

pip install -qU extract_msg
from langchain_community.document_loaders import OutlookMessageLoader

loader = OutlookMessageLoader("example_data/fake-email.msg")

data = loader.load()

data[0]
Document(page_content='This is a test email to experiment with the MS Outlook MSG Extractor\r\n\r\n\r\n-- \r\n\r\n\r\nKind regards\r\n\r\n\r\n\r\n\r\nBrian Zhou\r\n\r\n', metadata={'source': 'example_data/fake-email.msg', 'subject': 'Test for TIF files', 'sender': 'Brian Zhou [[email protected]](mailto:[email protected])', 'date': datetime.datetime(2013, 11, 18, 0, 26, 24, tzinfo=zoneinfo.ZoneInfo(key='America/Los_Angeles'))})

---

<Callout icon="pen-to-square" iconType="regular">
    [Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/document_loaders/email.mdx)
</Callout>
<Tip icon="terminal" iconType="regular">
    [Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for    real-time answers.
</Tip>
I