# mailcoil
Mailcoil is a small SMTP wrapper around Python's native functionality that
makes several tasks easier, namely constructing mails that contain referenced
inline attachments (e.g., images that are referenced from within HTML mail) or
signing/encrypting emails via CMS (commonly known as S/MIME). It also has
support for IMAP so that sent mails can be stored in a "Sent" folder using the
same mechanism as sending them through SMTP.
## Usage
For usage of mailcoil you first need to define a dropoff at which mails should
be posted. This is typically your MTA or smart relay:
```python3
dropoff = mailcoil.MailDropoff(mailcoil.MailDropoff.Scheme.SMTPS, "smtp.my-server.com")
```
You then can create an email:
```python3
mail = mailcoil.Email(from_address = "Johannes Bauer <johannes.bauer@gmx.de>", subject = "What's up?").to("someone@gmx.de")
```
CC and BCC are also supported using the same syntax as the `.to()` method:
```python3
mail.cc("cc1@gmx.de", "cc2@gmx.de").bcc("bcc@gmx.de")
```
Emails can use text/plain, text/html, or both bodies:
```python3
mail.text = "This is the text content!"
mail.html = "<html><body><h1>Hey!</h1><p>This is the HTML content!</body></html>"
```
To attach files to this mail, simply you can use the `attach` method:
```python3
mail.attach("foo.jpg")
```
By default, the Content-Disposition of attachments is "attachment". However,
you can also create "inline" attachments that you can then reuse in your HTML
portion, e.g.:
```python3
src_cid = mail.attach("foo.jpg", inline = True)
mail.html = f"<html><body><h1>Hey!</h1><p>This is the HTML content!<img src='${src_cid}'></body></html>"
```
By default, the Content-ID is auto-generated, which means that it depends on
the number of attachments. If you want fixed CIDs, you can also do that. Note
that You are then responsible for not creating collisions in the CIDs:
```python3
src_cid = mail.attach("foo.jpg", inline = True, cid = "foobar")
mail.html = f"<html><body><h1>Hey!</h1><p>This is the HTML content!<img src='cid:foobar'></body></html>"
```
If you wish to sign or encrypt mail using CMS (commonly known as S/MIME), you
need to set the security property of your email and configure it properly. For
example, for just signing, this works:
```python3
mail.security = mailcoil.CMS().sign(signer_keyfile = "my_key.pem", signer_certfile = "my_cert.pem", ca_certfile = "my_ca.pem")
```
If you additionally want to encrypt for three different targets, you can also
do:
```python3
mail.security.encrypt("target1.pem", "target2.pem", "target3.pem")
```
Similarly, you may also only encrypt without signing:
```python3
mail.security = mailcoil.CMS().encrypt("target.pem")
```
When your mail is finally set up, you can drop it off at the previously defined
dropoff:
```python3
dropoff.post(mail)
```
A complete example is therefore:
```python3
import mailcoil
dropoff = mailcoil.MailDropoff(mailcoil.MailDropoff.Scheme.SMTPS, "smtp.my-server.com")
mail = mailcoil.Email(from_address = "Johannes Bauer <johannes.bauer@gmx.de>", subject = "What's up?").to("someone@gmx.de")
mail.cc("cc1@gmx.de", "cc2@gmx.de").bcc("bcc@gmx.de")
mail.text = "This is the text content!"
# Attach file and use it in HTML portion
src_cid = mail.attach("foo.jpg", inline = True)
mail.html = f"<html><body><h1>Hey!</h1><p>This is the HTML content!<img src='${src_cid}'></body></html>"
# Sign and encrypt
mail.security = mailcoil.CMS().sign(signer_keyfile = "my_key.pem", signer_certfile = "my_cert.pem", ca_certfile = "my_ca.pem").encrypt("target1.pem", "target2.pem", "target3.pem")
dropoff.post(mail)
```
## License
GNU GPL-3.
Raw data
{
"_id": null,
"home_page": "https://github.com/johndoe31415/mailcoil",
"name": "mailcoil",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "mail, email, smtp, encrypted, cms, smime",
"author": "Johannes Bauer",
"author_email": "joe@johannes-bauer.com",
"download_url": "https://files.pythonhosted.org/packages/f3/7f/df8b53bde705ec20e518e7e55a4413908ce4422787ee455a82881109b808/mailcoil-0.0.4.tar.gz",
"platform": null,
"description": "# mailcoil\nMailcoil is a small SMTP wrapper around Python's native functionality that\nmakes several tasks easier, namely constructing mails that contain referenced\ninline attachments (e.g., images that are referenced from within HTML mail) or\nsigning/encrypting emails via CMS (commonly known as S/MIME). It also has\nsupport for IMAP so that sent mails can be stored in a \"Sent\" folder using the\nsame mechanism as sending them through SMTP.\n\n## Usage\nFor usage of mailcoil you first need to define a dropoff at which mails should\nbe posted. This is typically your MTA or smart relay:\n\n```python3\ndropoff = mailcoil.MailDropoff(mailcoil.MailDropoff.Scheme.SMTPS, \"smtp.my-server.com\")\n```\n\nYou then can create an email:\n\n```python3\nmail = mailcoil.Email(from_address = \"Johannes Bauer <johannes.bauer@gmx.de>\", subject = \"What's up?\").to(\"someone@gmx.de\")\n```\n\nCC and BCC are also supported using the same syntax as the `.to()` method:\n\n```python3\nmail.cc(\"cc1@gmx.de\", \"cc2@gmx.de\").bcc(\"bcc@gmx.de\")\n```\n\nEmails can use text/plain, text/html, or both bodies:\n\n```python3\nmail.text = \"This is the text content!\"\nmail.html = \"<html><body><h1>Hey!</h1><p>This is the HTML content!</body></html>\"\n```\n\nTo attach files to this mail, simply you can use the `attach` method:\n\n```python3\nmail.attach(\"foo.jpg\")\n```\n\nBy default, the Content-Disposition of attachments is \"attachment\". However,\nyou can also create \"inline\" attachments that you can then reuse in your HTML\nportion, e.g.:\n\n```python3\nsrc_cid = mail.attach(\"foo.jpg\", inline = True)\nmail.html = f\"<html><body><h1>Hey!</h1><p>This is the HTML content!<img src='${src_cid}'></body></html>\"\n```\n\nBy default, the Content-ID is auto-generated, which means that it depends on\nthe number of attachments. If you want fixed CIDs, you can also do that. Note\nthat You are then responsible for not creating collisions in the CIDs:\n\n```python3\nsrc_cid = mail.attach(\"foo.jpg\", inline = True, cid = \"foobar\")\nmail.html = f\"<html><body><h1>Hey!</h1><p>This is the HTML content!<img src='cid:foobar'></body></html>\"\n```\n\nIf you wish to sign or encrypt mail using CMS (commonly known as S/MIME), you\nneed to set the security property of your email and configure it properly. For\nexample, for just signing, this works:\n\n```python3\nmail.security = mailcoil.CMS().sign(signer_keyfile = \"my_key.pem\", signer_certfile = \"my_cert.pem\", ca_certfile = \"my_ca.pem\")\n```\n\nIf you additionally want to encrypt for three different targets, you can also\ndo:\n\n```python3\nmail.security.encrypt(\"target1.pem\", \"target2.pem\", \"target3.pem\")\n```\n\nSimilarly, you may also only encrypt without signing:\n\n```python3\nmail.security = mailcoil.CMS().encrypt(\"target.pem\")\n```\n\nWhen your mail is finally set up, you can drop it off at the previously defined\ndropoff:\n\n```python3\ndropoff.post(mail)\n```\n\nA complete example is therefore:\n\n```python3\nimport mailcoil\ndropoff = mailcoil.MailDropoff(mailcoil.MailDropoff.Scheme.SMTPS, \"smtp.my-server.com\")\nmail = mailcoil.Email(from_address = \"Johannes Bauer <johannes.bauer@gmx.de>\", subject = \"What's up?\").to(\"someone@gmx.de\")\nmail.cc(\"cc1@gmx.de\", \"cc2@gmx.de\").bcc(\"bcc@gmx.de\")\nmail.text = \"This is the text content!\"\n\n# Attach file and use it in HTML portion\nsrc_cid = mail.attach(\"foo.jpg\", inline = True)\nmail.html = f\"<html><body><h1>Hey!</h1><p>This is the HTML content!<img src='${src_cid}'></body></html>\"\n\n# Sign and encrypt\nmail.security = mailcoil.CMS().sign(signer_keyfile = \"my_key.pem\", signer_certfile = \"my_cert.pem\", ca_certfile = \"my_ca.pem\").encrypt(\"target1.pem\", \"target2.pem\", \"target3.pem\")\n\ndropoff.post(mail)\n```\n\n## License\nGNU GPL-3.\n",
"bugtrack_url": null,
"license": "gpl-3.0",
"summary": "Effortless, featureful SMTP",
"version": "0.0.4",
"project_urls": {
"Download": "https://github.com/johndoe31415/mailcoil/archive/v0.0.4.tar.gz",
"Homepage": "https://github.com/johndoe31415/mailcoil"
},
"split_keywords": [
"mail",
" email",
" smtp",
" encrypted",
" cms",
" smime"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f37fdf8b53bde705ec20e518e7e55a4413908ce4422787ee455a82881109b808",
"md5": "7e88a331d82ff8d9fba07d8b91da38e3",
"sha256": "6cdd38272fa0c81cc967667ce0926a22ca7fb53ddc10390b1469aef980fc03f3"
},
"downloads": -1,
"filename": "mailcoil-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "7e88a331d82ff8d9fba07d8b91da38e3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11540,
"upload_time": "2025-07-29T09:31:06",
"upload_time_iso_8601": "2025-07-29T09:31:06.021663Z",
"url": "https://files.pythonhosted.org/packages/f3/7f/df8b53bde705ec20e518e7e55a4413908ce4422787ee455a82881109b808/mailcoil-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-29 09:31:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "johndoe31415",
"github_project": "mailcoil",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "mailcoil"
}