About this project
sendsmtp is a small command-line SMTP client implemented in pure Python with no third-party dependencies. It composes a UTF-8 text/plain mail message and hands it to an SMTP server, making it usable for scripted notifications, build reports or piping command output into an email from a shell.
Installation and requirements
The package is installed with pip (python3 -m pip install --user --upgrade sendsmtp) and requires Python 3.11 or newer.
Basic usage
The command takes three positional arguments: HOST (hostname or IP of the SMTP server), FROM (used both as the SMTP envelope sender and the From header) and TO (one address or several comma-separated addresses with no spaces around the commas). A typical invocation sends the body inline with -m and the subject with -s, and reports success when the server accepts the message.
Message body sources
The body can come from three places. The -m/--message option supplies it inline. The -i/--input option reads it from a file path and takes precedence over --message; if the path is not an existing file the option is ignored and the body falls back to --message or stdin. If neither option is given, the body is read from stdin: piped input is read to EOF, while an interactive terminal triggers a prompt that reads lines until a line containing only EOF.
Subject handling
--subject/-s sets the subject explicitly. If it is omitted and the body begins with a Subject: line, that line is stripped from the body and used as the subject instead.
Connection security and ports
The client supports three modes. Plain SMTP defaults to port 25. --starttls connects in plain text and upgrades the connection using the STARTTLS extension, defaulting to port 587. -t/--tls uses implicit TLS from the first byte (SMTPS), defaulting to port 465. The two TLS options are mutually exclusive, and -p/--port overrides the default port in any mode.
Authentication
-u/--username enables SMTP AUTH; without it no AUTH attempt is made. If a username is given without --password, the password is prompted for interactively without echo. The documentation notes this is preferable because command lines can be visible to other processes and are recorded in shell history. Authentication failures abort the run and the message is not sent.
Recipients beyond TO
-c/--cc adds carbon-copy recipients who appear in the CC header and receive the message. -b/--bcc adds blind carbon-copy recipients who receive the message but are not listed in any header. Both accept comma-separated address lists.
Diagnostics
-v/--verbose prints the SMTP dialog to stderr, reports connection and authentication steps, lists the addresses the message was delivered to, and, on failure, shows the full stack trace instead of a one-line error. Without it, failures produce a single-line error message.
Message headers and exit codes
Generated messages carry From, To, Subject, CC (only with --cc) and an X-Mailer: sendsmtp header. Exit code 0 means the server accepted the message for every recipient, 1 indicates an error or at least one refused recipient, and 130 signals an interrupt with Ctrl-C.
Licensing
The project is released under the MIT license.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.