# ezmail
easily send out emails via python or the cli using python's SMTP module.
---
# Getting started
download the package using pip: `pip install ezmail`
## `.env` file
This module uses environment files to handle sensitive info.
Make sure the following values are defined in it:
```.env
USERNAME=sender@exmaple.com
PASSWORD=<password>
SMTP=<provider's SMTP server>
PORT=<provider's port>
```
See examples [below](https://github.com/Alex23rodriguez/ezmail/edit/main/README.md#smtp-servers) for popular providers.
## send from python
```python
from ezmail import send_mail
# by default, an env file named `.env` is searched.
send_mail(
subject="Email sent with Python",
recipients=["r1@example.com", "John Doe <john@example.com>"],
message="Here go the contents of the message.",
)
```
## send from the cli
`python -m ezmail -s "Email sent from bash" -r "r1@example.com" "r2@example.com" -m "This is my message."`
---
# More advanced uses
This module allows adding attachments to the email, as well as reading in the message and / or recipients from a file instead of defining them directly.
## python
Python automatically detects the type of data that is passed into the different fields.
For example, to read the recipients from a file, simply pass in a Path or file object instead of a list of strings.
A file that defines the recipients must have one recipient per line:
```recipients.txt
r1@example.com
John Doe <john@example.com>
```
The message can also be taken from a Path or file object. If the message contents are html, remember to set the `html` flag to True.
To add attachments, pass in a list of Paths or (read-binary) file objects. The type is automatically detected.
If an env file with a name different from `.env` is used, pass it into `envfile` as a Path object or a string
### For example:
```python
from pathlib import Path
from ezmail import send_mail
recipients_file = Path("path/to/recipients.txt")
messages_file = open("path/to/message.html", "r")
attachments = [
Path("path/to/attachment1.csv"),
open("path/to/attachment2.jpg", "rb"),
]
envfile = Path("my/.envfile")
send_mail(
subject="Email sent with Python",
recipients=recipients_file,
message=messages_file,
attachments=attachments,
envfile=envfile,
html=True,
)
```
## cli
`python -m ezmail --help` to see how to call from the command line
Possible flags:
- `-s` or `--subject`: the subject of the email (single argument)
- message:
- `-m` or `--message`: the contents of the email OR
- `-f` or `--file`: the file containing the contents of the email
- recipients:
- `-r` or `--recipients`: the recipients of the email (one or more arguments) OR
- `-rf` or `--recipientsfile`: the file containing the addresses of the recipients
- `-a` or `--attachments`: a list of files to attach to the email (one or more arguments)
- `-e` or `--env`: the env file where the credentials are defined (default `.env`)
- `-H` or `--html`: (flag) if present, the contents of the message will be sent as html
- `-v` or `--verbose`: set SMTP server debug level to 1, to debug possible connection issues
---
# Popular SMTP servers
Here is a brief description of popular SMTP servers.
If having trouble setting up the SMTP server, pass in `verbose=True` into the python method, or the flag `-v` on the cli version.
## gmail
Gmail constantly changes the requirements to be able to send out emails through SMTP. It is recommended that you follow a [guide](https://www.gmass.co/blog/gmail-smtp/).
Then, fill in the missing values from the following `.env` file
```.env
USERNAME=
PASSWORD=
SMTP="smtp.gmail.com"
PORT=465
```
# Zoho
Zoho makes it very simple to send emails through SMTP. Fill in the missing values from the following `.env` file and that's it!
```.env
USERNAME=
PASSWORD=
SMTP="smtp.zoho.com"
PORT=465
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Alex23rodriguez/ezmail",
"name": "ezmail",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "python,mail,smtp,cli",
"author": "Alex Rodriguez",
"author_email": "alex.rodriguez.oro@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e8/4d/56b28223d7f86d66f0b40852269b602355ee64a234d079f05929a20e4014/ezmail-1.0.3.tar.gz",
"platform": null,
"description": "# ezmail\n\neasily send out emails via python or the cli using python's SMTP module.\n\n---\n\n# Getting started\n\ndownload the package using pip: `pip install ezmail`\n\n## `.env` file\n\nThis module uses environment files to handle sensitive info.\nMake sure the following values are defined in it:\n\n```.env\nUSERNAME=sender@exmaple.com\nPASSWORD=<password>\nSMTP=<provider's SMTP server>\nPORT=<provider's port>\n```\n\nSee examples [below](https://github.com/Alex23rodriguez/ezmail/edit/main/README.md#smtp-servers) for popular providers.\n\n## send from python\n\n```python\nfrom ezmail import send_mail\n\n# by default, an env file named `.env` is searched.\nsend_mail(\n subject=\"Email sent with Python\",\n recipients=[\"r1@example.com\", \"John Doe <john@example.com>\"],\n message=\"Here go the contents of the message.\",\n)\n```\n\n## send from the cli\n\n`python -m ezmail -s \"Email sent from bash\" -r \"r1@example.com\" \"r2@example.com\" -m \"This is my message.\"`\n\n---\n\n# More advanced uses\n\nThis module allows adding attachments to the email, as well as reading in the message and / or recipients from a file instead of defining them directly.\n\n## python\n\nPython automatically detects the type of data that is passed into the different fields.\n\nFor example, to read the recipients from a file, simply pass in a Path or file object instead of a list of strings.\n\nA file that defines the recipients must have one recipient per line:\n\n```recipients.txt\nr1@example.com\nJohn Doe <john@example.com>\n```\n\nThe message can also be taken from a Path or file object. If the message contents are html, remember to set the `html` flag to True.\n\nTo add attachments, pass in a list of Paths or (read-binary) file objects. The type is automatically detected.\n\nIf an env file with a name different from `.env` is used, pass it into `envfile` as a Path object or a string\n\n### For example:\n\n```python\nfrom pathlib import Path\nfrom ezmail import send_mail\n\nrecipients_file = Path(\"path/to/recipients.txt\")\nmessages_file = open(\"path/to/message.html\", \"r\")\n\nattachments = [\n Path(\"path/to/attachment1.csv\"),\n open(\"path/to/attachment2.jpg\", \"rb\"),\n]\n\nenvfile = Path(\"my/.envfile\")\n\nsend_mail(\n subject=\"Email sent with Python\",\n recipients=recipients_file,\n message=messages_file,\n attachments=attachments,\n envfile=envfile,\n html=True,\n)\n```\n\n## cli\n\n`python -m ezmail --help` to see how to call from the command line\n\nPossible flags:\n\n- `-s` or `--subject`: the subject of the email (single argument)\n- message:\n - `-m` or `--message`: the contents of the email OR\n - `-f` or `--file`: the file containing the contents of the email\n- recipients:\n - `-r` or `--recipients`: the recipients of the email (one or more arguments) OR\n - `-rf` or `--recipientsfile`: the file containing the addresses of the recipients\n- `-a` or `--attachments`: a list of files to attach to the email (one or more arguments)\n- `-e` or `--env`: the env file where the credentials are defined (default `.env`)\n- `-H` or `--html`: (flag) if present, the contents of the message will be sent as html\n- `-v` or `--verbose`: set SMTP server debug level to 1, to debug possible connection issues\n\n---\n\n# Popular SMTP servers\n\nHere is a brief description of popular SMTP servers.\n\nIf having trouble setting up the SMTP server, pass in `verbose=True` into the python method, or the flag `-v` on the cli version.\n\n## gmail\n\nGmail constantly changes the requirements to be able to send out emails through SMTP. It is recommended that you follow a [guide](https://www.gmass.co/blog/gmail-smtp/).\n\nThen, fill in the missing values from the following `.env` file\n\n```.env\nUSERNAME=\nPASSWORD=\nSMTP=\"smtp.gmail.com\"\nPORT=465\n```\n\n# Zoho\n\nZoho makes it very simple to send emails through SMTP. Fill in the missing values from the following `.env` file and that's it!\n\n```.env\nUSERNAME=\nPASSWORD=\nSMTP=\"smtp.zoho.com\"\nPORT=465\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "easily send out emails via SMTP",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://github.com/Alex23rodriguez/ezmail"
},
"split_keywords": [
"python",
"mail",
"smtp",
"cli"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4e1b94d5277416b09130392c634ee9f6a7fdf6d223b239bc0e88faa025f42fc9",
"md5": "d67937bc9dc4c5a36de4e271618151e5",
"sha256": "c131a4c700bb46dc8a01d657d2fc17738eef6bd41d214402428324df017cf2b3"
},
"downloads": -1,
"filename": "ezmail-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d67937bc9dc4c5a36de4e271618151e5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 17430,
"upload_time": "2024-02-13T21:20:12",
"upload_time_iso_8601": "2024-02-13T21:20:12.695522Z",
"url": "https://files.pythonhosted.org/packages/4e/1b/94d5277416b09130392c634ee9f6a7fdf6d223b239bc0e88faa025f42fc9/ezmail-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e84d56b28223d7f86d66f0b40852269b602355ee64a234d079f05929a20e4014",
"md5": "efb332dbdf0f39264240177bbae91f13",
"sha256": "05a3fb39f98dbe301ecec6a29292f30794b99d58fe5190199a2693141cc85f8a"
},
"downloads": -1,
"filename": "ezmail-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "efb332dbdf0f39264240177bbae91f13",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 16797,
"upload_time": "2024-02-13T21:20:14",
"upload_time_iso_8601": "2024-02-13T21:20:14.293231Z",
"url": "https://files.pythonhosted.org/packages/e8/4d/56b28223d7f86d66f0b40852269b602355ee64a234d079f05929a20e4014/ezmail-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-13 21:20:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Alex23rodriguez",
"github_project": "ezmail",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ezmail"
}