https://github.com/drkostas/pyemail-sender
A utility for sending emails with attachments. Currently only Gmail is supported.
https://github.com/drkostas/pyemail-sender
email email-sender emailer gmail gmail-api gmailer
Last synced: 7 months ago
JSON representation
A utility for sending emails with attachments. Currently only Gmail is supported.
- Host: GitHub
- URL: https://github.com/drkostas/pyemail-sender
- Owner: drkostas
- License: apache-2.0
- Created: 2022-01-28T16:44:08.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-30T01:42:25.000Z (almost 4 years ago)
- Last Synced: 2025-03-15T12:11:28.277Z (8 months ago)
- Topics: email, email-sender, emailer, gmail, gmail-api, gmailer
- Language: Python
- Homepage: https://pypi.org/project/pyemail-sender/
- Size: 32.2 KB
- Stars: 20
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Python Emailer
[](https://pepy.tech/project/pyemail-sender)
[](https://github.com/drkostas/pyemail-sender/master/LICENSE)
[](https://circleci.com/gh/drkostas/pyemail-sender/tree/master)
A utility for sending emails with attachments. Currently only Gmail
is supported. [PYPI Package](https://pypi.org/project/pyemail-sender/)
## Table of Contents
+ [Using the library](#using)
+ [Installing and using the library](#install_use)
+ [Examples of usage](#examples)
+ [Manually install the library](#manual_install)
+ [Prerequisites](#prerequisites)
+ [Install the requirements](#installing_req)
+ [Run the Unit Tests](#unit_tests)
+ [Continuous Integration](#ci)
+ [Update PyPI package](#pypi)
+ [License](#license)
For a detailed usage example see
[example.py](https://github.com/drkostas/pyemail-sender/master/example.py).
You will need an application-specific password for your Google account.
[Reference 1](https://support.google.com/mail/?p=InvalidSecondFactor),
[Reference 2](https://security.google.com/settings/security/apppasswords)
### Installing and using the library
First, you need to install the library using pip:
```shell
$ pip install pyemail_sender
```
Then, import it and initialize it like so:
```python
from pyemail_sender import GmailPyEmailSender
email_conf = {'type': 'gmail',
'config': {'api_key': 'your api key', 'email_address': 'youremail@gmail.com'}}
pymail = GmailPyEmailSender(config=email_conf)
```
If you want to use a yml file to load the configuration, you can use the `PyEmailSenderConfig` class:
```python
from pyemail_sender import PyEmailSenderConfig
import os
config_path = str(os.path.join('confs', 'conf.yml'))
config = PyEmailSenderConfig(config_src=config_path)
email_conf = config.get_pyemail_sender_config()
```
Two example YAML files can be found in
the [confs folder](https://github.com/drkostas/pyemail-sender/blob/master/confs).
For more details on how to use this YAML configuration loader see
this [Readme](https://github.com/drkostas/yaml-config-wrapper/blob/master/README.md).
**Send Simple Email**
```python
pymail.send_email(subject='A simple email',
to=[email_conf['email_address']],
text='Email body text goes here')
```
**Send HTML Email**
```python
pymail.send_email(subject='A simple HTML email',
to=[email_conf['email_address']],
html='
Email body with HTML goes here
')
```
**Send Email with all the arguments**
```python
pymail.send_email(subject='Email with all possible arguments',
sender=email_conf['email_address'],
to=[email_conf['email_address']],
cc=[email_conf['email_address']],
bcc=[email_conf['email_address']],
reply_to=email_conf['email_address'],
html='Test HTML body
',
attachments=['my_file.txt'])
```
All of these examples can be found
in [example.py](https://github.com/drkostas/pyemail-sender/tree/blob/master/example.py).
## Manually install the library
These instructions will get you a copy of the project up and running on your local machine for
development and testing purposes.
You need to have a machine with
[anaconda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html) installed and
any Bash based shell (e.g. zsh) installed.
```ShellSession
$ conda -V
conda 4.10.1
$ echo $SHELL
/usr/bin/zsh
```
All the installation steps are being handled by
the [Makefile](https://github.com/drkostas/pyemail-sender/blob/master/Makefile).
First, modify the python version (`min_python`) and everything else you need in
the [settings.ini](https://github.com/drkostas/pyemail-sender/blob/master/settings.ini).
Then, execute the following commands:
```ShellSession
$ make create_env
$ conda activate pyemail_sender
$ make dist
```
Now you are ready to use and modify the library.
If you want to run the unit tests, execute the following command:
```ShellSession
$ make tests
```
For the continuous integration, the CircleCI service is being used. For more information you can
check the [setup guide](https://circleci.com/docs/2.0/language-python/).
For any modifications, edit
the [circleci config](https://github.com/drkostas/pyemail-sender/blob/master/.circleci/config.yml).
This is mainly for future reference for the developers of this project. First,
create a file called `~/.pypirc` with your pypi login details, as follows:
```
[pypi]
username = your_pypi_username
password = your_pypi_password
```
Then, modify the python version (`min_python`), project status (`status`), release version (`version`)
and everything else you need in
the [settings.ini](https://github.com/drkostas/pyemail-sender/blob/master/settings.ini).
Finally, execute the following commands:
```ShellSession
$ make create_env
$ conda activate pyemail_sender
$ make release
```
For a dev release, change the `testing_version` and instead of `make release`, run `make release_test`.
This project is licensed under the Apache License - see
the [LICENSE](https://github.com/drkostas/pyemail-sender/blob/master/LICENSE) file for details.