Table of contents
About xchange_mail
This python package was build for making the mail sending processing through exchangelib a little bit easier. The idea is to create some custom functions for a limited use cases, so the user won't need to configure or define details on Account or Config exchangelib classes, but rather execute basic functions for sending basic emails.
The examples section will clarify some use cases of xchange_mail package for helping users to send basic emails through MS Exchange. Keep watching this documentation.
Package Structure
At this time, the package is built around just one module called mail. This module contains some functions for helping users connecting with Exchange server and also sending basic mails with plain text or HTML body messages. The table below has the explanation of the main componentes of this mail module.
| Function | Short Description |
|---|---|
connect_exchange() |
Receives some user credentials for connecting to Exchange and returning an Account object |
attach_file() |
Stores a pandas DataFrame object on buffers and returns a two-elements list containing the attach name and the attach object |
format_mail_body() |
Creates a HTMLBody object. If a DataFrame is passed as an argument, it uses pretty_html_table package for customizing a table before creating the HTMLBody |
send_simple_mail() |
Sends a simple mail through exchange with possibilities for attaching one file, sending a DataFrame object on mail body, sending an image on mail body or attached or using html code for customizing mail |
send_mail_mult_files() |
Can send multiple files attached or multiple DataFrames on body |
Biblioteca python construída para facilitar o gerenciamento e envio de e-mails utilizando a biblioteca exchangelib como ORM da caixa de e-mails Exchange.
Installing the Package
The latest version of xchange_mail package are published and available on PyPI repository
:pushpin: Note: as a good practice for every Python project, the creation of a virtual environment is needed to get a full control of dependencies and third part packages on your code. By this way, the code below can be used for creating a new venv on your OS.
# Creating and activating venv on Linux
$ python -m venv <path_venv>/<name_venv>
$ source <path_venv>/<nome_venv>/bin/activate
# Creating and activating venv on Windows
$ python -m venv <path_venv>/<name_venv>
$ <path_venv>/<nome_venv>/Scripts/activate
With the new venv active, all you need is execute the code below using pip for installing the package (upgrading pip is optional):
$ pip install --upgrade pip
$ pip install xchange_mail
The xchange_mail package is built in an upper layer above some other python packages like exchangelib and pandas. So, when installing mlcomposer, the pip utility will also install all dependencies linked to the package.
Examples
After introducing the package, it's time to explain it in a deeper way: through examples. On this Github repository, it's possible to find some good uses of xchange_mail on examples/ folder. In practice, for sending a basic email it's possible to execute the send_simple_mail() function with few parameter configuration as seen below:
from xchange_mail.mail import send_simple_mail
# Extracting environment variables from a .env file (optional)
USERNAME = os.getenv('MAIL_FROM')
PWD = os.getenv('PASSWORD')
SERVER = 'outlook.office365.com'
MAIL_BOX = os.getenv('MAIL_BOX')
MAIL_TO = os.getenv('MAIL_TO')
# Sending a basic mail
send_simple_mail(username=USERNAME,
password=PWD,
server=SERVER,
mail_box=MAIL_BOX,
subject='This is a xchange_mail test',
mail_body='Testing the package by sending a simple mail',
mail_signature='Regards, xchange_mail developers',
mail_to=MAIL_TO)
Done! Almost all other package features are built around this send_simple_mail() function and the other one called send_mail_mult_files(). Just to clarify, there are some parameters that can be set on the function above for sending a pandas DataFrame attached on mail body, for example. There is also a feature for sending an image embedding on mail body. The code below is an example of sending a simple mail with a DataFrame object attached, on mail body with an image saved locally.
import pandas as pd
from xchange_mail.mail import send_simple_mail
# Extracting environment variables from a .env file (optional)
USERNAME = os.getenv('MAIL_FROM')
PWD = os.getenv('PASSWORD')
SERVER = 'outlook.office365.com'
MAIL_BOX = os.getenv('MAIL_BOX')
MAIL_TO = os.getenv('MAIL_TO')
# Sending a basic mail
send_simple_mail(username=USERNAME,
password=PWD,
server=SERVER,
mail_box=MAIL_BOX,
subject='This is a xchange_mail test',
mail_body='Testing the package by sending a simple mail',
mail_signature='Regards, xchange_mail developers',
mail_to=MAIL_TO,
df_on_body=True,
df_on_attachment=True,
df=df,
attachment_filename='pandas_dataframe.csv',
image_on_body=True,
image_location='/home/user/image_dir/image.png')
For new use cases, please take a look at examples/ folder on this repository.
Contribution
The xchange_mail python package is an open source implementation and the more people use it, the more happy the developers will be. So if you want to contribute with xchange_mail, please feel free to follow the best practices for implementing coding on this github repository through creating new branches, making merge requests and pointig out whenever you think there is a new topic to explore or a bug to be fixed.
Thank you very much for reaching this and it will be a pleasure to have you as xchange_mail user or developer.
Social Media
- Follow me on LinkedIn: https://www.linkedin.com/in/thiago-panini/
- See my other Python packages: https://github.com/ThiagoPanini
Metadata
Release files for xchange-mail 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| xchange_mail-0.0.7.tar.gz | 9.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xchange_mail-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.6 kB
Release files / xchange_mail-0.0.7.tar.gz
| Download URL | xchange_mail-0.0.7.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f399c1c4ae9ac31445e8df968b7210bed13145df8d3115c79c13b8328e11bb1c
|
|
BLAKE2b-256 checksum How to use checksums |
f7d540cc9f1016fcece3fcabaef47b946b09fbe2669446db633564d31ac6c997
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.6
|
Release files / xchange_mail-0.0.7-py3-none-any.whl
| Download URL | xchange_mail-0.0.7-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48b1e0ef548b2f415563732e7afc732dc701ecfc59eb041fe91fc9b51e8cc3ca
|
|
BLAKE2b-256 checksum How to use checksums |
acbfc2886cc96849e01c400cf0f01ec6eb383190e99bd0ce459d79e4106a96e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.6
|
Security for xchange-mail 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.