azure-mail

A Python package for sending emails in Office 365 via an Azure app

https://github.com/ucl-mirsg/azure-mail

Science Score: 52.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
    Organization ucl-mirsg has institutional domain (www.ucl.ac.uk)
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.3%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

A Python package for sending emails in Office 365 via an Azure app

Basic Info
  • Host: GitHub
  • Owner: UCL-MIRSG
  • License: mit
  • Language: Python
  • Default Branch: main
  • Size: 1.15 MB
Statistics
  • Stars: 3
  • Watchers: 2
  • Forks: 0
  • Open Issues: 3
  • Releases: 0
Created over 1 year ago · Last pushed 7 months ago
Metadata Files
Readme License Citation

README.md

Azure Mail

pre-commit Tests status Linting status Documentation status License

A Python package for sending emails in Office 365 via an Azure app

This project is developed in collaboration with the Centre for Advanced Research Computing, University College London.

About

Project Team

MIRSG

Research Software Engineering Contact

Centre for Advanced Research Computing, University College London (arc.collaborations@ucl.ac.uk)

Getting Started

Pre-requisites

  1. create an app in Azure for sending emails

Before using azure-mail, you will need to create an app in Azure with the necessary permissions to send emails on behalf of a user. For example, EWS.AccessAsUser.All Delegated permission within Office 365 Exchange Online scope should allow emails to be sent. This permission is described as "Access mailboxes as the signed-in user via Exchange Web Services" in the Azure portal.

  1. store the necessary credentials in a .envrc file

The credentials should be stored in a .envrc file in the root directory of the project. The file should container the following information:

shell # layout python export CLIENT_ID= export CLIENT_SECRET= export TENANT_ID= export ACCOUNT= export USERNAME= export USER_PASSWORD= export AUTHOR= export SCOPE= export SERVER=

Here's a brief explanation of each line above: - layout python: required for direnv to export the environment variables - CLIENT_ID: ID of the app created in Azure - CLIENT_SECRET: secret used by the app to authenticate to the email server - TENANT_ID: ID of the organisation in Azure - ACCOUNT : account to send emails from (e.g. abcdef@ucl.ac.uk) - USERNAME: username of sender (if at UCL, your UCL ID e.g. abcdefg) - USER_PASSWORD: password of sender - AUTHOR: emails address to send email from. Can be different to ACCOUNT if, for example, sending from a shared mailbox - SCOPE: scope of the account (e.g. https://outlook.office365.com/.default) - SERVER: server for exchanglib configuration (e.g. outlook.office365.com)

  1. [recommended] install and configure direnv to automatically export the credentials as environment variables

Install direnv and then grant it permission to load your .envrc file:

bash direnv allow .

Installation

We recommend installing in a project specific virtual environment created using a environment management tool such as Conda. To install the latest development version of azure-mail using pip in the currently active environment run

sh python -m pip install git+https://github.com/UCL-MIRSG/azure-mail.git

Alternatively create a local clone of the repository with

sh git clone https://github.com/UCL-MIRSG/azure-mail.git

and then install in editable mode by running

sh python -m pip install -e .

Usage Example

```python import azure_mail

Create a meeting invite to send as an attachment in your email

attachments = azuremail.createcalendarics( subject="Meeting", description="Very important all-day meeting", date="January 1, 1970", starthour=9, startminute=0, durationhours=8, duration_minutes=0, timezone="Europe/London", )

message = azuremail.createemail( recipients={'person1@mail.com', 'someone-else@mail.com'}, body=exchangelib.HTMLBody( "Hello, there's a meeting invite attached", ), subject='Meeting invite', attachments=attachments, )

Save email in Drafts folder

message.save()

Send email to recipients

message.send() ```

Overview

The ClientApplication from python msal library is used to connect to an app installed in Microsoft Azure with the relevant permissions. An access token is acquired through acquire_token_by_username_password firstly and then the access token is cached so acquire_token_silent to be used in future uses of this package. This provides the necessary credentials and configuration to access the UCL account from which the emails are sent.

Running Tests

Tests can be run across all compatible Python versions in isolated environments using tox by running

sh tox

To run tests manually in a Python environment with pytest installed run

sh pytest tests

again from the root of the repository.

Building Documentation

The MkDocs HTML documentation can be built locally by running

sh tox -e docs

from the root of the repository. The built documentation will be written to site.

Alternatively to build and preview the documentation locally, in a Python environment with the optional docs dependencies installed, run

sh mkdocs serve

Owner

UCL Medical Imaging Research Software Group

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
type: software
authors:
  - group-name: "Medical Imaging Research Software Group"
    email: "arc.medical-imaging@ucl.ac.uk"
repository-code: "https://github.com/UCL-MIRSG/azure-mail"
title:
  "Azure Mail: A Python package for sending emails in Office 365 via an Azure
  app"
license: "MIT"

GitHub Events

Total
  • Issues event: 1
  • Watch event: 2
  • Delete event: 23
  • Issue comment event: 12
  • Push event: 111
  • Pull request review comment event: 4
  • Pull request review event: 17
  • Pull request event: 34
  • Create event: 28
Last Year
  • Issues event: 1
  • Watch event: 2
  • Delete event: 23
  • Issue comment event: 12
  • Push event: 111
  • Pull request review comment event: 4
  • Pull request review event: 17
  • Pull request event: 34
  • Create event: 28

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 9
  • Average time to close issues: N/A
  • Average time to close pull requests: 2 days
  • Total issue authors: 0
  • Total pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 1.11
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 5
Past Year
  • Issues: 0
  • Pull requests: 9
  • Average time to close issues: N/A
  • Average time to close pull requests: 2 days
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 1.11
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 5
Top Authors
Issue Authors
  • ruaridhg (2)
  • renovate[bot] (1)
Pull Request Authors
  • renovate[bot] (23)
  • ruaridhg (6)
  • p-j-smith (1)
Top Labels
Issue Labels
enhancement (2)
Pull Request Labels
renovate (22)

Dependencies

.github/workflows/docs.yml actions
  • actions/cache 0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 composite
  • actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
  • actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
  • peaceiris/actions-gh-pages 4f9cc6602d3f66b9c108549d475ec49e8ef4d45e composite
.github/workflows/linting.yml actions
  • actions/cache 0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 composite
  • actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
  • actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
.github/workflows/tests.yml actions
  • actions/cache 0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 composite
  • actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
  • actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
pyproject.toml pypi
  • exchangelib *
  • ics *
  • msal *
  • pytz *