# smtpymailer
[![Python Unittest](https://github.com/arched-dev/smtpymailer/actions/workflows/main.yml/badge.svg)](https://github.com/arched-dev/smtpymailer/actions/workflows/main.yml)
[![Python Coverage](https://github.com/arched-dev/smtpymailer/blob/master/tests/assets/coverage.svg)](https://github.com/arched-dev/smtpymailer/actions/workflows/main.yml)
## Introduction
`smtpymailer` is a versatile Python library designed to simplify the process of sending emails in python. It supports
and validates DKIM, DMARC, and SPF records before sending emails to avoid being marked as spam, so it is ideal for sending
emails from your own mail server but the sender is an alternative domain.
## Features
- Login to any mail server of your choice (I maintain a postfix server for outgoing mail only, so replies are still directed to the users normal inbox).
- Send emails from different domains, provided the correct DNS settings are in place.
- Validates DNS settings like DKIM, DMARC, and SPF before sending emails to avoid being marked as spam.
- Full email functionality including `To`, `CC`, `BCC`, `Reply-To`, and attachments.
- Adds attachments with the correct MIME type.
- Optionally converts url <img> tags to inline attachments CID attachments or Base64 encoded img sources, this is controlled by data attributes `data-inline` or `data-base` in the img tag.
- Supports sending string HTML content, Jinja templates, or plain html files.
- Automatically converts HTML to plain text for email clients that do not support HTML.
- Supports environment variables and `.env` files for mail server settings.
## Installation
Install the package using `pip`:
```bash
pip install smtpymailer
```
## Usage
### Initialization
Create an instance of `SmtpyMailer` with your sender email and name. The mail server details can be passed as keyword
arguments or sourced from environment variables or a `.env` file.
### Environment Variables
The following environment variables can be set or added to a `.env` file in your project root.
Alternatively you can pass as **kwargs to the `SmtpyMailer` class but this is not advised.
- `MAIL_SERVER`: The mail server hostname.
- `MAIL_PORT`: The mail server port.
- `MAIL_USE_TLS`: Whether to use TLS or not.
- `MAIL_USERNAME`: The mail server username.
- `MAIL_PASSWORD`: The mail server password.
- `MAIL_DKIM_SELECTOR`: The DKIM selector of the domain you are sending from. (This is used to validate your ability to send from the domain).
```python
from smtpymailer import SmtpMailer
mailer = SmtpMailer(sender_email="foo@bar.com", sender_name="Foo Bar")
```
### Sending an Email
Use the `send_email` method to send emails:
#### Parameters
- `recipients`: Single recipient email or a list of email addresses.
- `subject`: Email subject.
- `cc_recipients`: (Optional) Single or list of CC email addresses.
- `bcc_recipients`: (Optional) Single or list of BCC email addresses.
- `reply_to`: (Optional) Reply-to email address.
- `attachments`: (Optional) Single file path or list of file paths for attachments.
- `html_content`: (Optional) HTML content of the email (not required if using a template)
- `template`: (Optional) Template file path (using jinja), it can be just a plain html file.
- `template_directory`: (Optional) Single or list of template directories.
- `**kwargs`: Additional arguments for jinja template, if needed.
### Example
- Send a simple email with a subject and html content.
```python
from smtpymailer import SmtpMailer
mailer = SmtpMailer(sender_email="foo@bar.com", sender_name="Foo Bar")
mailer.send_email(recipients="bar@baz.com", subject="My test email", html_content="<h1>Hello World</h1>")
```
- Send to multiple recipients, one CC, with an attachment, and a jinja template with kwargs.
```python
from smtpymailer import SmtpMailer
mailer = SmtpMailer(sender_email="foo@bar.com", sender_name="Foo Bar")
template_data = {"name": "Foo Bar", "message": "Hello Foo", "url": "https://www.foo.com"}
mailer.send_email(recipients=["bar@baz.com", "baz@bar.com"], cc_recipients="foo@baz.com", subject="My test email", template="template.html", template_directory="./templates", **template_data)
```
## Sending From Alternative Domains
You can send emails from alternative domains by setting up the correct DNS settings. Here's how to do it.
[Alt Domains Documentation](./docs/ALT_DOMAINS.md)
## License
This project is licensed under the [MIT License](LICENSE).
## TODO
- Change the way the send function's `alter_img_src` parameter works. It should AUTODETECT img elements with `data-inline` or `data-base` attributes instead.
****
Raw data
{
"_id": null,
"home_page": "https://github.com/lewis-morris/smtpymailer",
"name": "smtpymailer",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Lewis Morris",
"author_email": "lewis@arched.dev",
"download_url": "https://files.pythonhosted.org/packages/9a/f8/5735d4942b38ebf6d2ca39a19fa89a2d4a3cbb46a0272dbee7df59da444d/smtpymailer-0.1.2.tar.gz",
"platform": null,
"description": "\n# smtpymailer\n\n[![Python Unittest](https://github.com/arched-dev/smtpymailer/actions/workflows/main.yml/badge.svg)](https://github.com/arched-dev/smtpymailer/actions/workflows/main.yml)\n\n[![Python Coverage](https://github.com/arched-dev/smtpymailer/blob/master/tests/assets/coverage.svg)](https://github.com/arched-dev/smtpymailer/actions/workflows/main.yml)\n\n\n\n## Introduction\n`smtpymailer` is a versatile Python library designed to simplify the process of sending emails in python. It supports\nand validates DKIM, DMARC, and SPF records before sending emails to avoid being marked as spam, so it is ideal for sending \nemails from your own mail server but the sender is an alternative domain.\n\n\n## Features\n- Login to any mail server of your choice (I maintain a postfix server for outgoing mail only, so replies are still directed to the users normal inbox).\n- Send emails from different domains, provided the correct DNS settings are in place.\n- Validates DNS settings like DKIM, DMARC, and SPF before sending emails to avoid being marked as spam.\n- Full email functionality including `To`, `CC`, `BCC`, `Reply-To`, and attachments.\n- Adds attachments with the correct MIME type.\n- Optionally converts url <img> tags to inline attachments CID attachments or Base64 encoded img sources, this is controlled by data attributes `data-inline` or `data-base` in the img tag.\n- Supports sending string HTML content, Jinja templates, or plain html files.\n- Automatically converts HTML to plain text for email clients that do not support HTML.\n- Supports environment variables and `.env` files for mail server settings.\n\n## Installation\nInstall the package using `pip`:\n\n```bash\npip install smtpymailer\n```\n\n## Usage\n\n### Initialization\n\nCreate an instance of `SmtpyMailer` with your sender email and name. The mail server details can be passed as keyword\narguments or sourced from environment variables or a `.env` file.\n\n### Environment Variables\n\nThe following environment variables can be set or added to a `.env` file in your project root.\nAlternatively you can pass as **kwargs to the `SmtpyMailer` class but this is not advised.\n\n- `MAIL_SERVER`: The mail server hostname.\n- `MAIL_PORT`: The mail server port.\n- `MAIL_USE_TLS`: Whether to use TLS or not.\n- `MAIL_USERNAME`: The mail server username.\n- `MAIL_PASSWORD`: The mail server password.\n- `MAIL_DKIM_SELECTOR`: The DKIM selector of the domain you are sending from. (This is used to validate your ability to send from the domain).\n\n\n```python\nfrom smtpymailer import SmtpMailer\nmailer = SmtpMailer(sender_email=\"foo@bar.com\", sender_name=\"Foo Bar\")\n```\n\n### Sending an Email\n\nUse the `send_email` method to send emails:\n\n\n#### Parameters\n\n- `recipients`: Single recipient email or a list of email addresses.\n- `subject`: Email subject.\n- `cc_recipients`: (Optional) Single or list of CC email addresses.\n- `bcc_recipients`: (Optional) Single or list of BCC email addresses.\n- `reply_to`: (Optional) Reply-to email address.\n- `attachments`: (Optional) Single file path or list of file paths for attachments.\n- `html_content`: (Optional) HTML content of the email (not required if using a template)\n- `template`: (Optional) Template file path (using jinja), it can be just a plain html file.\n- `template_directory`: (Optional) Single or list of template directories.\n- `**kwargs`: Additional arguments for jinja template, if needed.\n\n### Example\n\n- Send a simple email with a subject and html content.\n\n```python\nfrom smtpymailer import SmtpMailer\nmailer = SmtpMailer(sender_email=\"foo@bar.com\", sender_name=\"Foo Bar\")\nmailer.send_email(recipients=\"bar@baz.com\", subject=\"My test email\", html_content=\"<h1>Hello World</h1>\")\n```\n\n- Send to multiple recipients, one CC, with an attachment, and a jinja template with kwargs.\n\n```python\nfrom smtpymailer import SmtpMailer\nmailer = SmtpMailer(sender_email=\"foo@bar.com\", sender_name=\"Foo Bar\")\ntemplate_data = {\"name\": \"Foo Bar\", \"message\": \"Hello Foo\", \"url\": \"https://www.foo.com\"}\nmailer.send_email(recipients=[\"bar@baz.com\", \"baz@bar.com\"], cc_recipients=\"foo@baz.com\", subject=\"My test email\", template=\"template.html\", template_directory=\"./templates\", **template_data)\n```\n## Sending From Alternative Domains\n\nYou can send emails from alternative domains by setting up the correct DNS settings. Here's how to do it.\n[Alt Domains Documentation](./docs/ALT_DOMAINS.md)\n\n## License\nThis project is licensed under the [MIT License](LICENSE).\n\n## TODO\n- Change the way the send function's `alter_img_src` parameter works. It should AUTODETECT img elements with `data-inline` or `data-base` attributes instead.\n****\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A emailing python library for emailing from alternative domains - DNS entries etc need to be assigned (not used for spamming).",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/lewis-morris/smtpymailer"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "62422a070badec185012a6feb79fabe2bee5fe8b208e92bfdfe9b317cddf8010",
"md5": "80f67b32960f360c14bfb16558a98bd1",
"sha256": "350ff87528c4461d80511edf9bdab00b3b57d3f520cf958ed95a89c65da8599f"
},
"downloads": -1,
"filename": "smtpymailer-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "80f67b32960f360c14bfb16558a98bd1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 19594,
"upload_time": "2024-11-08T18:51:56",
"upload_time_iso_8601": "2024-11-08T18:51:56.002268Z",
"url": "https://files.pythonhosted.org/packages/62/42/2a070badec185012a6feb79fabe2bee5fe8b208e92bfdfe9b317cddf8010/smtpymailer-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9af85735d4942b38ebf6d2ca39a19fa89a2d4a3cbb46a0272dbee7df59da444d",
"md5": "c4d4192202a883c29dd54f9a7f14101c",
"sha256": "b9a61d45027cf21222ad630392f13fcb65c66b6c8ff61fe37ea26d3962530aeb"
},
"downloads": -1,
"filename": "smtpymailer-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "c4d4192202a883c29dd54f9a7f14101c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 29183,
"upload_time": "2024-11-08T18:51:58",
"upload_time_iso_8601": "2024-11-08T18:51:58.041018Z",
"url": "https://files.pythonhosted.org/packages/9a/f8/5735d4942b38ebf6d2ca39a19fa89a2d4a3cbb46a0272dbee7df59da444d/smtpymailer-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-08 18:51:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lewis-morris",
"github_project": "smtpymailer",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "beautifulsoup4",
"specs": [
[
"==",
"4.12.3"
]
]
},
{
"name": "cryptography",
"specs": [
[
"==",
"42.0.1"
]
]
},
{
"name": "dmarc",
"specs": [
[
"==",
"1.0.3"
]
]
},
{
"name": "dnspython",
"specs": [
[
"==",
"2.5.0"
]
]
},
{
"name": "email-validator",
"specs": [
[
"==",
"2.1.0.post1"
]
]
},
{
"name": "html2text",
"specs": [
[
"==",
"2020.1.16"
]
]
},
{
"name": "pillow",
"specs": [
[
"==",
"10.2.0"
]
]
},
{
"name": "pydig",
"specs": [
[
"==",
"0.4.0"
]
]
},
{
"name": "pytest",
"specs": [
[
"==",
"8.0.0"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
"==",
"1.0.1"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.31.0"
]
]
},
{
"name": "validators",
"specs": [
[
"==",
"0.22.0"
]
]
},
{
"name": "python-magic",
"specs": [
[
"==",
"0.4.27"
]
]
},
{
"name": "jinja2",
"specs": [
[
"==",
"3.0.3"
]
]
}
],
"lcname": "smtpymailer"
}