Skip to main content

Allows scripts to send email to a preconfigured address.

Project description


``notifymail`` allows scripts to send email to a preconfigured address.
It is particularly useful for unattended and scheduled scripts to report
their status to an administrator.

``notifymail`` is designed to be very easy to install and use. I wrote
it because I couldn't figure out how to configure the built-in
``sendmail`` command to forward emails appropriately and I couldn't get
the similar ``ssmtp`` package to work.


- OS X or Linux
- Python 2.6 or 2.7
- An email account



$ pip install notifymail


You must know the SMTP settings of your email provider, which can
typically looked up on your provider's website. For example here are
`Gmail's SMTP
settings <,1665162>`__,
obtained with a internet search for "gmail SMTP settings":

- **Gmail SMTP Server:**
- **Gmail SMTP Port:** 587 (for TLS)
- **Gmail SMTP Uses TLS?** yes

Usually your SMTP username will be the same as your email address, and
your SMTP password will be the same as your email password.

Once you have the settings in hand, run the `` --setup``


$ --setup
SMTP Server Hostname:
SMTP Server Port [465]: 587
SMTP Server Uses TLS (y/n) [n]: yes
SMTP Username:
SMTP Password: ********
From Address []:
From Name (optional) []: notifymail
To Address:

Verifying connection to SMTP server... OK


From the Command Line


$ echo "Hello World" | -s "Subject"

``notifymail`` will read the message body from standard input and allow
you to specify a subject line with the ``-s`` option. You may also
specify a custom sender name using the ``--from-name`` option.

The encoding of the message body and all arguments is assumed to be

Full usage information:


Usage: --setup | -s SUBJECT [-b BODY] [--from-name NAME] | --probe

-h, --help show this help message and exit
--setup setup mail server configuration
--probe check whether mail server is reachable
-s SUBJECT, --subject=SUBJECT
subject line. Required.
-b BODY, --body=BODY body. Read from standard input if omitted.
--from-name=NAME sender name. Overrides the default sender name.

From a Python Script


import notifymail
notifymail.send("Subject", "Hello World")

String arguments can be either Unicode strings or UTF-8 encoded

From a Non-Python Script

Just execute the ``notifymail`` command using your language's normal API
for running system commands.

For example, in Ruby:


require 'open3'

Open3.popen3('', '-s', 'Subject') {|stdin, stdout, stderr, wait_thr|
stdin.puts('Hello World!')

exit_code = wait_thr.value.to_i
if exit_code != 0
raise "notifymail exited with error code #{exit_code}."

For example, in Java:



try {
Process notifymail = Runtime.getRuntime().exec(new String[] {
"", "-s", "Subject" });
PrintStream stdin = new PrintStream(
notifymail.getOutputStream(), /*autoFlush=*/false, "UTF-8");

stdin.println("Hello World!");

int exitCode = notifymail.waitFor();
if (exitCode != 0) {
throw new Exception("notifymail exited with error code " + exitCode + ".");
} catch (Exception e) {
throw new RuntimeException("Unable to send email.", e);


- The configured SMTP settings are stored in plaintext, including the
SMTP password.


This code is provided under the MIT License.

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

notifymail-1.0.tar.gz (5.7 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page