Code Monkey home page Code Monkey logo

smtpc's Introduction

SMTPc

smtpc version smtpc license smtpc python compatibility Downloads say thanks!

SMTPc is a simple SMTP client for easy mail sending using CLI. It's dedicated for developers, however it's easy to use and every CLI user will be satisfied using this.

The main purpose of SMTPc is to help developers test and/or verify SMTP servers or their SMTP configuration. Of course, it can be used in every place you want to automate any system, and use predefined messages (with templates) for notifications, like daemons or crons.

If you like this tool, just say thanks.

Current stable version

0.7.0

Features

  • Predefined profiles for use with many SMTP servers
  • Predefined messages for sending messages just by referencing the message name
  • Automatically build message from given parameters, do not glue headers manually
  • Store passwords in an encrypted form (optionally)
  • Ability to edit raw message body just before sending
  • Templating system customizing messages (with Jinja2)
  • SSL and TLS connections, of course
  • You can easily spoof your own messages, by specifying other sender/recipient in message headers, and other one for SMTP session
  • Easily add custom email headers
  • If you have multiple IP addresses available, choose which one you want to use
  • It's all Python!

Installation

SMTPc should work on any POSIX platform where Python is available. This includes Linux, macOS/OSX etc.

The simplest way is to use Python's built-in package system:

python3 -m pip install 'smtpc[extended]'

It will install SMTPc and related packages for the best user experience. If you want to install the basic version without additions, then start with:

python3 -m pip install smtpc

You can also use pipx if you don't want to mess with system packages and install SMTPc in virtual environment:

pipx install smtpc

Voila!

Python version

SMTPc is tested against Python 3.7+. Older Python versions may work, or may not.

How to use

First, add the account that you want to use for sending. In this example we are using Sendria, which runs on our local environment:

smtpc profiles add sendria --host 127.0.0.1 --port 1025

You can verify that the profile is stored:

smtpc profiles list

Now, add a few messages for future use:

smtpc messages add plain --subject 'Some plain email' --body-plain 'Some plain message body' --from [email protected] --to [email protected]
smtpc messages add html --subject 'Some html email' --body-html 'Some <b>HTML</b> message body' --from [email protected] --to [email protected]
smtpc messages add alternative --subject 'Some alternative email' --body-plain 'Some plain message body' --body-html 'Some <b>HTML</b> message body' --from [email protected] --to [email protected]

You can verify that your messages are stored:

smtpc messages list

Now, lets send some emails:

smtpc send --profile sendria --message alternative
smtpc send --profile sendria --message plain --subject 'Changed subject for plain'

In the second example above, we are using a predefined message named plain, but with a changed subject.

You don't need to use any predefined profiles or messages. You can just pass them directly when sending:

smtpc send --host 127.0.0.1 --port 1025 --body-type html --subject 'Some html email' --body-html 'Some <b>HTML</b> message body' --from [email protected] --to [email protected]

But it's not where the fun is :)

You can also use your predefined messages as templates:

smtpc messages add template-test --subject 'Some templated email: {{ date }}' --body-plain 'Some templated email body: {{ uuid }}' --from [email protected] --to [email protected]
smtpc send --profile sendria --message template-test --template-field "date=$(date)" --template-field "uuid=$(uuidgen)"

So when the email is received, the subject will look like this:

Some templated email: Thu Mar 18 19:05:53 CET 2021

and the body will look like this:

Some templated email body: C21B7FF0-C6BC-47C9-B3AC-5554865487E4

If Jinja2 module is available, you can use it as a templating engine! See more in Templating chapter.

Templating

Templating can be done in both simple and extended forms. In the simplest case, when Jinja2 module is not found, SMTPc can only substitute simple placeholders with data.

For example, if you specify the subject as:

--subject "Now we have {{ date }}"

and when sending you provide a value:

--template-field "date=$(date +"%Y-%m-%dT%H:%M:%S%Z")"

then in the final email it will look like:

Now we have 2021-03-19T10:56:31CET

But if you want to add conditions, loops or any other more complex syntax, you will need to install Jinja2 module (more: Installation).

You willl then have the full power of one of best templating engines Python has. Here's an example:

smtpc messages add template-test --subject 'Some of my projects, state on {{ date }}' --from [email protected] --to [email protected] --body-html '<p>Here I am!</p>
{% if projects %}
<p>Some of my projects:</p>
<ul>
{% for project in projects %}
    <li><a href="https://github.com/msztolcman/{{ project }}">{{ project }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>I have no projects to show :(</p>
{% endif %}
<p>That&#39;s all folks!</p>'
smtpc send --profile sendria --message template-test --template-field "date=$(date -u +'%Y-%m-%dT%H:%M:%S%Z')" --template-field-json='projects=["sendria", "smtpc", "versionner", "ff"]'

So when the email is received, the subject will look like this:

Some of my projects, state on 2021-03-19T10:03:56UTC

and the body (slightly reformatted here):

<p>Here I am!</p>
<p>Some of my projects:</p>
<ul>
    <li><a href="https://github.com/msztolcman/sendria">sendria</a></li>
    <li><a href="https://github.com/msztolcman/smtpc">smtpc</a></li>
    <li><a href="https://github.com/msztolcman/versionner">versionner</a></li>
    <li><a href="https://github.com/msztolcman/ff">ff</a></li>
</ul>
<p>That&#39;s all folks!</p>

You can read more about Jinja2 capabilities on Jinja2 homepage.

Authors

Contact

If you like or dislike this software, please do not hesitate to tell me about it via email ([email protected]).

If you find a bug or have an idea to enhance this tool, please use GitHub's issues.

ChangeLog

v0.8.0

  • send and profiles commands: ask for password if --password param was used with no argument
  • when adding a new profile, you can choose to encrypt your password. In this case you will be asked for encryption key. The same key must be used to decrypt password when sending.

v0.7.0

  • added --message-interactive param for send command. Allows editing of raw message body just before sending
  • changed url in User-Agent header and when --version is called to smtpc.net
  • many internal fixes and rewrites, added few new tests

v0.6.0

  • added --template-field and --template-field-json params for send command, allows to replace some {{ fields }} in email body or subject with specified values. Or you can also use Jinja2 if module is installed

v0.5.0

  • safe writing config files: will show file content if writing will fail
  • messages list is simplified by default (just message name like in profiles list)
  • new commands: smtpc profiles delete, smtpc messages delete - self explanatory I guess :)
  • few minor bugs squashed
  • few internal changes and improvements

v0.4.1

  • fixed handling --ssl and --tls when sending message using profile
  • added simple --dry-run option
  • added --reply-to option
  • minor fixes to error handling
  • added User-Agent header to generated messages

v0.4.0

  • BC: renamed command: profile -> profiles
  • added new command: messages for managing of saved email messages
  • allow overwriting profile or message predefined options from CLI arguments
  • cleaner and more elegant code

v0.3.0

  • using commands now instead of dozens of CLI arguments

v0.2.0

  • added profiles

v0.1.1

  • fixed --version

v0.1.0

  • very initial version

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.