p3mail - Send terminal outputs by mail
p3mail (Pathetic Python Pipe Mail) allows you to send terminal outputs by mail
Basically something like this
./long_running_command_printing_logs | p3mail "My mail's subject"
Since it is highly probable that you are both the sender and receiver, these latter are pre-defined in a config file (see below).
Important note Remember that only stdout is captured when using pipes. You may want to redirect stderr to stdout to also catch errors. For example
./my_command_printing_errors 2>&1 | p3mail "My mail's subject"
Note: the order of stdout and stderr outputs is not preserved :( See: https://hisham.hm/2016/11/24/fun-hack-to-redirect-stdout-and-stderr-in-order/
Install
pip install p3mail
Usage
Using config file
Copy the config_example file to $HOME/.config/p3mail/config and start using p3mail !
See the examples below.
Using command line
usage: p3mail [-h] [--to TO] [--from DEST] [--config CONFIG] subject
positional arguments:
subject The subject of the mail
optional arguments:
-h, --help show this help message and exit
--to TO The receiver's address. If not provided, it will look at
the config file
--from DEST The sender's address. If not provided, it will look at the
config file
--config CONFIG Specify a custom location for the config file
Examples
Send backup logs by mail
my_backup_program | p3mail "Backup for `hostname` on `date`"
Cronjob notification
If your cron job is ran by root p3mail will look at /home/root/.config/p3mail/config
which is not something you might want. You can specify the config file location with:
echo "Hello msg body" | p3mail --config /home/alice/.config/p3mail/config "My subject"
Tip: you can put an alias in your .bashrc to avoid specifying this file everytime
like this:
p3mail="p3mail --config /home/alice/.config/p3mail/config"
Motivation
I coded this application because it is always painful (at least for me) to make the built-in mail service work (or whatever it is called on Linux distributions). Here are some other reasons:
- You don't always have the rights to configure this mail service (e.g. on a remote server)
sendmail,mailor other mail sender command line tools are not always installed or configured on the machines you are using- p3mail only requires that Python 3 is installed
- p3mail does not requires sudo rights
- p3mail needs a reason to live
Security concerns
You may not want to hardcode your smtp user or your smtp password in a config file. I understand that so p3mail allows you to read your credentials from environment variables.
- In your
configset as an empty value for either/bothSmtpUser/SmtpPasse.g.SmtpPass = - Then call
p3maillike this:
export SMTP_USER=alice
export SMTP_PASS=super_secr3t_passw0rd
./my_verbose_script | p3mail "Verbose script report"
TODO
- Add Gmail oauth support
Release files for p3mail 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| p3mail-0.1.1.tar.gz | 3.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| p3mail-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.3 kB
Release files / p3mail-0.1.1.tar.gz
| Download URL | p3mail-0.1.1.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2787cf6776235cba0a9f058047ac766b9855c5a3ce13f3f920dd0a7cac15a3d
|
|
BLAKE2b-256 checksum How to use checksums |
7877847030e3a287eee80e8c9a0302a53ec95374e8f058eb18df26587bb851c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / p3mail-0.1.1-py3-none-any.whl
| Download URL | p3mail-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca7989561583e2ef4e75c646744a4f795f7e0a5e4c8c11fe593b765508af9fde
|
|
BLAKE2b-256 checksum How to use checksums |
7bd757e285a2f935516b4a63d0bd223b8746f768b88aae12b1695fbdf5ff58ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |