Skip to main content

sendsmtp

CLI SMTP client in pure Python. No dependencies, one command: it builds a UTF-8 text/plain message — text/html with --html, multipart/mixed once files are attached — and hands it to an SMTP server.

Installation

python3 -m pip install --user --upgrade sendsmtp

Requires Python 3.11 or newer.

Quick start

$ sendsmtp smtp.example.com me@example.com you@example.com -s "Hi" -m "Hello!"
Message successfully sent.

Synopsis

sendsmtp [-h] [-m MESSAGE] [-i INPUT] [--html] [-p PORT] [-u USERNAME]
         [--password PASSWORD] [-t | --starttls] [-c CC] [-b BCC]
         [-s SUBJECT] [-a PATH] [-v]
         HOST FROM TO

Arguments

HOST

Hostname or IP address of the SMTP server to connect to.

$ sendsmtp smtp.example.com me@example.com you@example.com -m "hi"

FROM

Sender address, used both as the SMTP envelope sender (MAIL FROM) and as the From: header.

TO

Recipient address, or several addresses separated by commas — no spaces around the commas.

$ sendsmtp smtp.example.com me@example.com "a@example.com,b@example.com" -m "hi"

Options

-m MESSAGE, --message MESSAGE

Message body, given inline.

$ sendsmtp smtp.example.com me@example.com you@example.com -m "Deploy finished."

-i INPUT, --input INPUT

Path to a file to read the message body from. Takes precedence over --message. If the path is not an existing file the option is ignored and the body is taken from --message or from stdin instead.

$ sendsmtp smtp.example.com me@example.com you@example.com -i report.txt

If neither --message nor --input is given, the body is read from stdin. Piped input is read to EOF:

$ dmesg | tail -n 20 | sendsmtp smtp.example.com me@example.com you@example.com -s "dmesg"

When stdin is a terminal, sendsmtp prompts and reads lines until a line containing only EOF:

$ sendsmtp smtp.example.com me@example.com you@example.com
Please, provide message contents. Type 'EOF' for end.
First line.
Second line.
EOF
Message successfully sent.

--html

Send the body as text/html instead of text/plain. The body itself is taken from --message, --input or stdin as usual — the flag only changes the content type, nothing is escaped or wrapped.

$ sendsmtp smtp.example.com me@example.com you@example.com \
    -s "Report" -i report.html --html

No plain-text alternative part is generated: the message is a single text/html part, so clients that refuse HTML show it as markup.

-s SUBJECT, --subject SUBJECT

Message subject.

$ sendsmtp smtp.example.com me@example.com you@example.com -s "Nightly build" -m "green"

If --subject is not given and the body starts with a Subject: line, that line is stripped from the body and used as the subject:

$ printf 'Subject: From the body\n\nBody text.\n' \
    | sendsmtp smtp.example.com me@example.com you@example.com

-p PORT, --port PORT

SMTP port. Defaults depend on the security mode: 25 for plain, 587 with --starttls, 465 with --tls.

$ sendsmtp smtp.example.com me@example.com you@example.com -p 2525 -m "hi"

-t, --tls

Use implicit TLS — the connection is encrypted from the first byte (SMTPS, port 465 by default). Mutually exclusive with --starttls.

$ sendsmtp smtp.example.com me@example.com you@example.com -t -u me@example.com -m "hi"

--starttls

Connect in plain text and upgrade the connection with the STARTTLS extension (port 587 by default). Mutually exclusive with --tls.

$ sendsmtp smtp.example.com me@example.com you@example.com --starttls -u me@example.com -m "hi"

-u USERNAME, --username USERNAME

Username for SMTP authentication. Without it no AUTH is attempted.

--password PASSWORD

Password for SMTP authentication. If --username is given but --password is not, the password is asked for interactively and is not echoed — preferable, since command lines are visible to other processes and land in the shell history.

$ sendsmtp smtp.example.com me@example.com you@example.com --starttls -u me@example.com -m "hi"
me@example.com's passwd:

Authentication failures abort the run; the message is not sent.

-c CC, --cc CC

Carbon-copy recipient(s), comma separated. The addresses appear in the CC: header and receive the message.

$ sendsmtp smtp.example.com me@example.com you@example.com -c "boss@example.com" -m "hi"

-b BCC, --bcc BCC

Blind carbon-copy recipient(s), comma separated. They receive the message but are not listed in any header.

$ sendsmtp smtp.example.com me@example.com you@example.com -b "archive@example.com" -m "hi"

-a PATH, --attach PATH

Attach a file to the message. Repeat the option once per file; the message then becomes multipart/mixed with the body as its first part.

$ sendsmtp smtp.example.com me@example.com you@example.com \
    -s "Nightly report" -m "See attached." -a report.pdf -a data.csv

The content type is guessed from the file name, falling back to application/octet-stream. A missing path is reported before the SMTP connection is opened, so nothing is sent and no password is asked for.

-v, --verbose

Print the SMTP dialog to stderr, report the connection and authentication steps, list the addresses the message was delivered to, and, on failure, let the full stacktrace through instead of a one-line error.

$ sendsmtp smtp.example.com me@example.com you@example.com -m "hi" -v
Connected to smtp.example.com:25 (plain).
send: 'ehlo host.example.com\r\n'
reply: b'250 smtp.example.com\r\n'
...
Message successfully sent to you@example.com

-h, --help

Print the usage summary and exit.

Headers

The generated message carries From:, To:, Subject:, CC: (only with --cc) and X-Mailer: sendsmtp.

Exit codes

Code

Meaning

0

Message accepted by the server for every recipient.

1

Error, or at least one recipient was refused.

130

Interrupted with Ctrl-C.

On failure only a single-line error is printed; pass --verbose to get the SMTP dialog and the full stacktrace.

License

MIT. See LICENSE.

Metadata

Release files for sendsmtp 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sendsmtp 2.0.0
File Size Uploaded
sendsmtp-2.0.0.tar.gz 72.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sendsmtp 2.0.0
File Interpreter ABI Platform
sendsmtp-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 82.6 kB

Release files / sendsmtp-2.0.0.tar.gz

Download URL sendsmtp-2.0.0.tar.gz
Size 72.8 kB
Tags Source
SHA-256 checksum
How to use checksums
660d69cf64cdd205417682c6982a2703b30f7594b1b480ba28842190ade808ba
BLAKE2b-256 checksum
How to use checksums
8473121cebc131adeb5bee14132a3d98715accb426ebbe240520afb24d198bcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release files / sendsmtp-2.0.0-py3-none-any.whl

Download URL sendsmtp-2.0.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4759ac9699c4aadc2c4278946d0183b772aa478835bc61317c01abd9a5956181
BLAKE2b-256 checksum
How to use checksums
649a9e2a9da58b6b45577394ba302de413ebdf3a5d0185c44f8dd782f0da9ea5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release history Release notifications | RSS feed

2.0.1

2 release files

This release

2.0.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page