Skip to main content

A utility for sending emails with attachments. Currently only Gmail is supported.

Project description

Python Emailer

CircleCI GitHub license

About

A utility for sending emails with attachments. Currently only Gmail is supported. PYPI Package

Table of Contents

Using the library

For a detailed usage example see example.py.

You will need an application-specific password for your Google account. Reference 1, Reference 2

Installing and using the library

First, you need to install the library using pip:

$ pip install pyemail_sender

Then, import it and initialize it like so:

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:

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. For more details on how to use this YAML configuration loader see this Readme.

Examples of usage

Send Simple Email

pymail.send_email(subject='A simple email',
                  to=[email_conf['email_address']],
                  text='Email body text goes here')

Send HTML Email

pymail.send_email(subject='A simple HTML email',
                  to=[email_conf['email_address']],
                  html='<h1>Email body with HTML goes here</h1>')

Send Email with all the arguments

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='<h1>Test <b>HTML</b> body</h1>',
                  attachments=['my_file.txt'])

All of these examples can be found in 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.

Prerequisites

You need to have a machine with anaconda installed and any Bash based shell (e.g. zsh) installed.

$ conda -V
conda 4.10.1

$ echo $SHELL
/usr/bin/zsh

Install the requirements

All the installation steps are being handled by the Makefile.

First, modify the python version (min_python) and everything else you need in the settings.ini.

Then, execute the following commands:

$ make create_env
$ conda activate pyemail_sender
$ make dist

Now you are ready to use and modify the library.

Run the Unit Tests

If you want to run the unit tests, execute the following command:

$ make tests

Continuous Integration

For the continuous integration, the CircleCI service is being used. For more information you can check the setup guide.

For any modifications, edit the circleci config.

Update PyPI package

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.

Finally, execute the following commands:

$ 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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Buy Me A Coffee

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyemail-sender-1.0.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

pyemail_sender-1.0.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file pyemail-sender-1.0.1.tar.gz.

File metadata

  • Download URL: pyemail-sender-1.0.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for pyemail-sender-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3aada31b98bf18deca57c111179ad2fdbef7ba69dd91c7c22f435560f802518d
MD5 be079b0d403829334739a170d897b197
BLAKE2b-256 8941c25fa5f00ea15395e01967989c08e37a6bd939bacf02b3742cec0e87f360

See more details on using hashes here.

File details

Details for the file pyemail_sender-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyemail_sender-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for pyemail_sender-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a7782cc6c1f05a0668d7f14e85c646f40ee9b85a7e4c2e942811967652fc9d6
MD5 36d9adf25919b613ba4be850cae8cbb0
BLAKE2b-256 ac21069efde6bef65632773d5b5009b16556a34a833b9523880ffd9669356dff

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page