Skip to main content

Send a formatted email from the command line

Project description

Send Mail Via Python (smvp)


smvp logo

The smvp utility takes a file whose contents will be parsed and packaged into the body of an email message, then sent to a designated email address. The input file can be a text file with ANSI color codes, HTML, or plain text. The resulting email will be sent as a multi-part MIME message that renders properly in both plain text and HTML.

Note: The file itself is not sent as an attachment; instead, the contents of the file are put into the body of the email.

Use Case

There are probably a few, but I wrote smvp for two primary reasons:

  1. I found that fiddling with postfix and sendmail was a pain.
  2. I want my cron scripts to email me status information and the contents of various log files. Some of the files contain ANSI escape sequences for terminal colors. The smvp utility converts those ANSI escape sequences into proper HTML tags, so the emails I get are nicely formatted. You could set $MAILTO in your crontab, but you won't get proper handling of ANSI escape sequences, and refer to number 1 above.

Installation

Use your preferred Python package installer for command line tools, for example:

pipx install smvp

or

uv tool install smvp

or

python3 -m venv .venv
source .venv/bin/activate
pip3 install smvp

Requirements

First

Make sure the following environment variables are set and exported in your current shell:

export SMVP_USER="<your email>"    # e.g. "myemail@gmail.com"
export SMVP_TOKEN="<your token>"   # e.g. "<gmail app password>"
export SMVP_SERVER="<smtp server>" # e.g. "smtp.gmail.com"

It is recommended that you put the lines above in your "rc" file (.bashrc, .zshrc, etc.) for use across multiple shell sessions and processes. To confirm you have the environment variables correctly set (with the correct spellings), run this in a terminal:

set | grep ^SMVP_

Note: If you make changes to your "rc" file, make sure to source it or open a new terminal window before running smvp again.


Tip: If you're using cron and sending mail with smvp from within a script, make sure to include the environment variables at the top of your crontab so your scripts will have access to them during execution. Also include a line in your script that exports the directory path where your Python tool installer puts things. For example, if you're using uv on Ubuntu, you would put something like this near the top of your bash script:

# Setup PATH export so the script can find installed Python tools
export PATH="$PATH:/home/<yourhome>/.local/bin"

Second

The SMVP_SERVER you select must support secure TLS connections on port 587. Check the SMTP settings for your email provider. This is the default TLS port on Gmail, so if you're using your Gmail account to send emails, you're good to go.

Styling

smvp offers custom font and font size options for your email. The default font for formatted HTML email is Courier New, 12px. Beyond the default, you can choose any font size from 2px up to and including 100px, from among these font families:

"Andale Mono", "Arial", "Brush Script MT", "Comic Sans MS",
"Courier New", "Garamond", "Georgia", "Helvetica", "Impact",
"Luminari", "Monaco", "Tahoma", "Times New Roman", "Trebuchet MS",
"Verdana", "fantasy", "monospace", "sans-serif", "serif"

Note: Not every font will render properly on every device. When in doubt, fonts like: "monospace", "sans-serif", "fantasy", and "serif" are pretty safe. You may just have to try a few options to land on the right one for your use case.

Usage

usage: smvp [-h] [-f FONT_FAMILY] [-s FONT_SIZE] [-v] recipient subject file

For example:

smvp friend@gmail.com "Hello, Friend" ~/logfile.txt -f "Trebuchet MS" -s 14

For more details, run:

smvp -h

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

smvp-0.2.12.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smvp-0.2.12-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file smvp-0.2.12.tar.gz.

File metadata

  • Download URL: smvp-0.2.12.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for smvp-0.2.12.tar.gz
Algorithm Hash digest
SHA256 84fc05b5b0f739a08bd5e80b377487ae8ae7fd197874cec61c4ae02ae28a39cb
MD5 8a21a2fdba9bf4006ef14af48c6f0218
BLAKE2b-256 6d7980be618ee3581e50e5c002ce535a323d4d48cab9d1de6776348e08e95271

See more details on using hashes here.

File details

Details for the file smvp-0.2.12-py3-none-any.whl.

File metadata

  • Download URL: smvp-0.2.12-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for smvp-0.2.12-py3-none-any.whl
Algorithm Hash digest
SHA256 963168a3f2ef9ba89a0a37af2bf743675cd59dfc4a341779dbaf9cdaa50ec3ba
MD5 3680d5eca116548cf87f9a1e90695de1
BLAKE2b-256 f58ef20d8f7be40930f64d4e1e10f4d7614393cef24771717023fee6544b738d

See more details on using hashes here.

Supported by

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