Skip to main content

Solução de gerenciamento e envio de e-mails via MS Exchange

Project description

xchange_mail logo

📧 Sending emails with basic formatting using exchangelib 📧

PyPI PyPI - Python Version PyPI - Status

Downloads Downloads Downloads


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

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

xchange_mail-0.0.7.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

xchange_mail-0.0.7-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file xchange_mail-0.0.7.tar.gz.

File metadata

  • Download URL: xchange_mail-0.0.7.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for xchange_mail-0.0.7.tar.gz
Algorithm Hash digest
SHA256 f399c1c4ae9ac31445e8df968b7210bed13145df8d3115c79c13b8328e11bb1c
MD5 e686a0821d6ddb168a72ea28ae444c08
BLAKE2b-256 f7d540cc9f1016fcece3fcabaef47b946b09fbe2669446db633564d31ac6c997

See more details on using hashes here.

File details

Details for the file xchange_mail-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: xchange_mail-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for xchange_mail-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 48b1e0ef548b2f415563732e7afc732dc701ecfc59eb041fe91fc9b51e8cc3ca
MD5 45d25700aa0628e7d4de9dffac425347
BLAKE2b-256 acbfc2886cc96849e01c400cf0f01ec6eb383190e99bd0ce459d79e4106a96e0

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