Name | docx2msg JSON |
Version |
0.1.2
JSON |
| download |
home_page | |
Summary | Convert a docx to an Outlook Mail-Item. |
upload_time | 2024-02-28 11:19:41 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.8 |
license | MIT |
keywords |
convert
docx
msg
outlook
mail
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# docx2msg
Converts a docx to an Outlook Mail-Item with few lines of code.
[![PyPI](https://img.shields.io/pypi/v/docx2msg)](https://pypi.org/project/docx2msg/)
[![PyPI - License](https://img.shields.io/pypi/l/docx2msg)](https://pypi.org/project/docx2msg/)
## Description
`docx2msg` is a python package that allows you to convert Microsoft Word .docx files to Outlook Mail-Item and .msg files. It provides a simple and efficient way to automate the conversion process, making it easier to automate with outlook email in your workflows.
## Features
- Convert a docx to an Outlook Mail-Item just using Word and Outlook Application without any third-party library.
- Set mail properties from the header of the docx in YAML format.
- Able to use docx-template to render the docx body and set mail properties dynamically.
## Requirements
- OS: Windows
- Application: Microsoft Word, Microsoft Outlook
- Python: 3.8+
- Python Packages: pywin32, python-docx, docx-template, pyyaml
## Installation
```shell
pip install docx2msg
```
## User Guide
### Quickstart
> The example docx file are coming soon...
1. Edit the body of the docx file to set the mail body as a normal docx file saving at "path/to/your/docx".
> You are recommand to edit the docx file with Microsoft Word Application in web layout mode to avoid the unexpected format issue.
2. Edit the header of the docx file to set the mail properties. The header should be in YAML format in this way:
```yaml
Subject: Demo email
To: anyone@example.com
CC: p1@example.com;p2@example.com
Attachments: path/to/your/attachment1.docx;path/to/your/attachment2.msg
Importance: High
Sensitivity: Confidential
ReadReceiptRequested: True
Categories: RED CATEGORY, BLUE CATEGORY
FlagRequest: Test Flag
ReminderTime: 2024-02-29 14:00:00
```
3. Convert a docx to an Outlook Mail-Item with few lines of code:
```python
import win32com.client
from docx2msg import Docx2Msg
docx_path = r"path/to/your/docx"
with Docx2Msg(docx_path) as docx:
# set display=True to display the mail in Outlook Application
mail = docx.convert(display=True)
```
4. The mail will be displayed in Outlook Application and you can see the output.
### Advanced Usage with template
Since `docx2msg` uses `docx-template` to render the docx body, you can use the same syntax to render the docx body and set mail properties dynamically.
You can access the `template` attribute of the `Docx2Msg` object to utilize the `docx-template` features.
> Go to [python-docx-template’s documentation](https://docxtpl.readthedocs.io/en/latest/) for more details.
Run the following code to convert a docx to an Outlook Mail-Item with a template:
```python
# the context to render the docx
context = {
"name": "John Doe",
"age": 30,
"address": "123 Main St."
}
with Docx2Msg(docx_path) as docx:
# use template attribute to render the docx body
docx.template.render(context)
# convert the docx to an Outlook Mail-Item
mail = docx.convert()
# display the mail in Outlook Application
mail.Display()
# save mail in draft folder
mail.Save()
# save mail as .msg file
mail.SaveAs(r"path/to/your/output.msg")
```
The output from `convert` method will be a `MailItem` object, for further development, you can refer to the [Outlook API](https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem) for more details.
### Mail Headers Syntax
The mail headers are in YAML format in the header of the docx file. The following properties are supported:
| Property | Type | Example |
|-----------------------------|----------|-----------------------------------------------|
| To | str\|list[str]| anyone@example.com |
| CC | str\|list[str]| p1@example.com;p2@example.com |
| BCC | str\|list[str]| p1@example.com;p2@example.com |
| Subject | str | Demo email |
| Attachments | str\|list[str] | path/to/your/file1.docx;path/to/your/file2.msg |
| Categories | str | RED CATEGORY, BLUE CATEGORY |
| Importance | str\|int | High |
| Sensitivity | str\|int | Confidential |
| ReadReceiptRequested | bool | True |
|OriginatorDeliveryReportRequested| bool | True |
| FlagRequest | str | Follow up |
| VotingOptions | str | Yes;No |
| ReminderTime | datetime | 2024-02-29 14:00:00 |
|DeferredDeliveryTime | datetime | 2024-02-29 14:00:00 |
|ExpiryTime | datetime | 2024-02-29 14:00:00 |
|FlagDueBy | datetime | 2024-02-29 14:00:00 |
|ReplyRecipients | str\|list[str]| p1@example.com;p2@example.com |
|SaveSentMessageFolder | str | 1/Auto/New |
**Note:**
For the some properties like `Attachments`, `To`, `CC`, `ReplyRecipients` which may have a list of values, you can use the `;` to separate them.
For the `SaveSentMessageFolder` property, the example "1/Auto/New" refers to the folder access by `outlook.Session.Folders[1].Folders["Auto"].Folder["New"]` in python code, which is the sugar syntax for the `SaveSentMessageFolder` property.
All the properties are vaild properties for `Outlook.MailItem` object, so you can refer to https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem#properties for more details.
### API Documentation
> The API documentation is coming soon...
## References
- pywin32: https://pypi.org/project/pywin32/
- Outlook API: https://learn.microsoft.com/en-us/office/vba/api/overview/outlook
- Word API: https://learn.microsoft.com/en-us/office/vba/api/overview/word
- docxtpl: http://docxtpl.readthedocs.org/
- jinja2: https://jinja.palletsprojects.com/en/3.0.x/
Raw data
{
"_id": null,
"home_page": "",
"name": "docx2msg",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "convert,docx,msg,outlook,mail",
"author": "",
"author_email": "Algebra-FUN <algebra-fun@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/f1/51/0ffc4ad7c3193d06d3f04d28218ed46200c94b59625e16ce07c4d04aadf2/docx2msg-0.1.2.tar.gz",
"platform": null,
"description": "# docx2msg\r\n\r\nConverts a docx to an Outlook Mail-Item with few lines of code.\r\n\r\n[![PyPI](https://img.shields.io/pypi/v/docx2msg)](https://pypi.org/project/docx2msg/)\r\n[![PyPI - License](https://img.shields.io/pypi/l/docx2msg)](https://pypi.org/project/docx2msg/)\r\n\r\n## Description\r\n\r\n`docx2msg` is a python package that allows you to convert Microsoft Word .docx files to Outlook Mail-Item and .msg files. It provides a simple and efficient way to automate the conversion process, making it easier to automate with outlook email in your workflows.\r\n\r\n## Features\r\n\r\n- Convert a docx to an Outlook Mail-Item just using Word and Outlook Application without any third-party library.\r\n- Set mail properties from the header of the docx in YAML format.\r\n- Able to use docx-template to render the docx body and set mail properties dynamically.\r\n\r\n## Requirements\r\n\r\n- OS: Windows\r\n- Application: Microsoft Word, Microsoft Outlook\r\n- Python: 3.8+\r\n- Python Packages: pywin32, python-docx, docx-template, pyyaml\r\n\r\n## Installation\r\n\r\n```shell\r\npip install docx2msg\r\n```\r\n\r\n## User Guide\r\n\r\n### Quickstart\r\n\r\n> The example docx file are coming soon...\r\n\r\n1. Edit the body of the docx file to set the mail body as a normal docx file saving at \"path/to/your/docx\".\r\n\r\n > You are recommand to edit the docx file with Microsoft Word Application in web layout mode to avoid the unexpected format issue.\r\n\r\n2. Edit the header of the docx file to set the mail properties. The header should be in YAML format in this way:\r\n\r\n ```yaml\r\n Subject: Demo email\r\n To: anyone@example.com\r\n CC: p1@example.com;p2@example.com\r\n Attachments: path/to/your/attachment1.docx;path/to/your/attachment2.msg\r\n Importance: High\r\n Sensitivity: Confidential\r\n ReadReceiptRequested: True\r\n Categories: RED CATEGORY, BLUE CATEGORY\r\n FlagRequest: Test Flag\r\n ReminderTime: 2024-02-29 14:00:00\r\n ```\r\n\r\n3. Convert a docx to an Outlook Mail-Item with few lines of code:\r\n\r\n ```python\r\n import win32com.client\r\n from docx2msg import Docx2Msg\r\n\r\n docx_path = r\"path/to/your/docx\"\r\n with Docx2Msg(docx_path) as docx:\r\n # set display=True to display the mail in Outlook Application\r\n mail = docx.convert(display=True)\r\n ```\r\n\r\n4. The mail will be displayed in Outlook Application and you can see the output.\r\n\r\n### Advanced Usage with template\r\n\r\nSince `docx2msg` uses `docx-template` to render the docx body, you can use the same syntax to render the docx body and set mail properties dynamically.\r\n\r\nYou can access the `template` attribute of the `Docx2Msg` object to utilize the `docx-template` features.\r\n\r\n> Go to [python-docx-template\u2019s documentation](https://docxtpl.readthedocs.io/en/latest/) for more details.\r\n\r\nRun the following code to convert a docx to an Outlook Mail-Item with a template:\r\n\r\n```python\r\n# the context to render the docx\r\ncontext = {\r\n \"name\": \"John Doe\",\r\n \"age\": 30,\r\n \"address\": \"123 Main St.\"\r\n}\r\nwith Docx2Msg(docx_path) as docx:\r\n # use template attribute to render the docx body\r\n docx.template.render(context)\r\n # convert the docx to an Outlook Mail-Item\r\n mail = docx.convert()\r\n # display the mail in Outlook Application\r\n mail.Display()\r\n # save mail in draft folder\r\n mail.Save()\r\n # save mail as .msg file\r\n mail.SaveAs(r\"path/to/your/output.msg\")\r\n```\r\n\r\nThe output from `convert` method will be a `MailItem` object, for further development, you can refer to the [Outlook API](https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem) for more details.\r\n\r\n### Mail Headers Syntax\r\n\r\nThe mail headers are in YAML format in the header of the docx file. The following properties are supported:\r\n\r\n\r\n| Property | Type | Example |\r\n|-----------------------------|----------|-----------------------------------------------|\r\n| To | str\\|list[str]| anyone@example.com |\r\n| CC | str\\|list[str]| p1@example.com;p2@example.com |\r\n| BCC | str\\|list[str]| p1@example.com;p2@example.com |\r\n| Subject | str | Demo email |\r\n| Attachments | str\\|list[str] | path/to/your/file1.docx;path/to/your/file2.msg |\r\n| Categories | str | RED CATEGORY, BLUE CATEGORY |\r\n| Importance | str\\|int | High |\r\n| Sensitivity | str\\|int | Confidential |\r\n| ReadReceiptRequested | bool | True |\r\n|OriginatorDeliveryReportRequested| bool | True |\r\n| FlagRequest | str | Follow up |\r\n| VotingOptions | str | Yes;No |\r\n| ReminderTime | datetime | 2024-02-29 14:00:00 |\r\n|DeferredDeliveryTime | datetime | 2024-02-29 14:00:00 |\r\n|ExpiryTime | datetime | 2024-02-29 14:00:00 |\r\n|FlagDueBy | datetime | 2024-02-29 14:00:00 |\r\n|ReplyRecipients | str\\|list[str]| p1@example.com;p2@example.com |\r\n|SaveSentMessageFolder | str | 1/Auto/New |\r\n\r\n**Note:**\r\n\r\nFor the some properties like `Attachments`, `To`, `CC`, `ReplyRecipients` which may have a list of values, you can use the `;` to separate them.\r\n\r\nFor the `SaveSentMessageFolder` property, the example \"1/Auto/New\" refers to the folder access by `outlook.Session.Folders[1].Folders[\"Auto\"].Folder[\"New\"]` in python code, which is the sugar syntax for the `SaveSentMessageFolder` property.\r\n\r\nAll the properties are vaild properties for `Outlook.MailItem` object, so you can refer to https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem#properties for more details.\r\n\r\n### API Documentation\r\n\r\n> The API documentation is coming soon...\r\n\r\n## References\r\n- pywin32: https://pypi.org/project/pywin32/\r\n- Outlook API: https://learn.microsoft.com/en-us/office/vba/api/overview/outlook\r\n- Word API: https://learn.microsoft.com/en-us/office/vba/api/overview/word\r\n- docxtpl: http://docxtpl.readthedocs.org/\r\n- jinja2: https://jinja.palletsprojects.com/en/3.0.x/\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Convert a docx to an Outlook Mail-Item.",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/Algebra-FUN/docx2msg",
"Repository": "https://github.com/Algebra-FUN/docx2msg"
},
"split_keywords": [
"convert",
"docx",
"msg",
"outlook",
"mail"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "756c69537067652459b0e86fdcbbc87bf687f9a2fe3a35ae68c511fd22608d3d",
"md5": "846f9d162a8b08131062597c9a9032cb",
"sha256": "f3f839e6d9fc2efb13d4e093514dc73e623b1634e812e00af7335baf62ce0f2b"
},
"downloads": -1,
"filename": "docx2msg-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "846f9d162a8b08131062597c9a9032cb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8512,
"upload_time": "2024-02-28T11:19:40",
"upload_time_iso_8601": "2024-02-28T11:19:40.496839Z",
"url": "https://files.pythonhosted.org/packages/75/6c/69537067652459b0e86fdcbbc87bf687f9a2fe3a35ae68c511fd22608d3d/docx2msg-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f1510ffc4ad7c3193d06d3f04d28218ed46200c94b59625e16ce07c4d04aadf2",
"md5": "cb5455fe7e866b38a6be72ac512bfc6b",
"sha256": "1fc30b9ae4d2cadcdc82f56e2087e2ed70efbcaaa3d78a1a4acc2ab6a80a12d1"
},
"downloads": -1,
"filename": "docx2msg-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "cb5455fe7e866b38a6be72ac512bfc6b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9505,
"upload_time": "2024-02-28T11:19:41",
"upload_time_iso_8601": "2024-02-28T11:19:41.672727Z",
"url": "https://files.pythonhosted.org/packages/f1/51/0ffc4ad7c3193d06d3f04d28218ed46200c94b59625e16ce07c4d04aadf2/docx2msg-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-28 11:19:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Algebra-FUN",
"github_project": "docx2msg",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "docx2msg"
}