Skip to main content

Simple CLI tool to generate/send valid RFC822 email messages (with DKIM optionally)

Project description

testmsg

Generate RFC822 compliant e-mail messages for tests and send it over SMTP.

While it's easy to send test messages like echo asdf | mail you@gmail.com or via telnet mx.example.com 25 I need a tool which:

  • Generates valid messages
  • Messages does not looks spammy or very suspicious
  • Easy to use and repeat test
  • Ability to customize messages
  • Work well with msmtp or other full-featured SMTP client (e.g. which can send over secure SMTP connection with authentication)
  • Support DKIM signatures

Installation

pip3 install testmsg

or

pipx install testmsg

Usage examples

$ testmsg --to you@gmail.com  --lorem 
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Subject: Sent with github.com/yaroslaff/testmsg
From: from@example.com
To: you@gmail.com

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempo=
r incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut al=
iquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore =
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia des=
erunt mollit anim id est laborum.

Options

Sending message

To actually send message via SMTP server add --send localhost or (if you need really powerful SMTP client features) pipe to msmtp:

testmsg --lorem --to you@gmail.com --from you@example.net | msmtp --host mail.example.net -v --tls=on --tls-starttls=on --auth=on --user=you@example.com --passwordeval "echo YourPass" -f you@example.net you@gmail.com

Customize message

Use --from, --to and --subject to override basic properties of message, use --add HEADER VALUE to add custom header(s).

Default message text is empty, use --text "blah blah blah" or --lorem or --msg PATH or --msg - .(to read from stdin). Add --time to add current time as an prefix to text.

Add attachments

Use --attachment (or --att) to add attachments: --att FILE1 FILE2 ...

Sign with DKIM

Generate DKIM RSA keys:

# generate private RSA key for DKIM
openssl genrsa -out example.com.pem 1024
# generate public key for DKIM
openssl rsa -in example.com.pem -out example.com.pub -pubout

Make DKIM DNS record with as SELECTOR._domainkey.example.com and verify it (here I decide to use selector mail):

$ host -t txt mail._domainkey.example.com
mail._domainkey.example.com.net descriptive text "v=DKIM1; h=sha256; k=rsa; p=MII...."

send DKIM signed message to gmail or mail-tester.com! Use --selector and --privkey arguments.

testmsg -f test@example.com -t mailbox@gmail.com --lorem --selector mail --privkey example.com.pem -v --send localhost

Use with authentication and SSL/STARTTLS SMTP servers

To use authentication, use --user and --password (or --pass) parameters. Use --ssl to use SSL-capable SMTP server (port 465), or use --starttls to use STARTTLS SMTP command. If neither --ssl nor --starttls is given, message and authentication credentials are sent over plain unencrypted connection, which is highly insecure.

If --user is not given (but --password given), testmsg will use username same as from (--from / -f) address.

Example:

testmsg -v -f test1@example.com -t somebody@example.net --lorem --pass "MyTestPass" --send mx.example.com --starttls

Use together with msmtp

Here we send with TLS and authentication (using msmtp). Username for authentication (--user) is same as FROM address. Testmsg generates valid message and msmtp sends it.

FROM=sender@example.com
TO=recipient@gmail.com

testmsg -f $FROM -t $TO --lorem | msmtp -v --host smtp.office365.com --port 587 --user $FROM --passwordeval='echo MyTestPass' -f $FROM --tls=on --auth=on $TO

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

testmsg-0.0.10.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

testmsg-0.0.10-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file testmsg-0.0.10.tar.gz.

File metadata

  • Download URL: testmsg-0.0.10.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for testmsg-0.0.10.tar.gz
Algorithm Hash digest
SHA256 1974fb2a56978acd0aa07b6448cc0d2eebdaeea8bdde36ae36049d9052df4fe8
MD5 e8725539b596148eeb53b53a9646159d
BLAKE2b-256 534b3db59c2ab5e2071d90ac67c32666cd8edd2b2d86b5e3549cd76d3e2ca347

See more details on using hashes here.

File details

Details for the file testmsg-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: testmsg-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for testmsg-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 9708784b2bd73100d7c8a08d2e6519790251b35a21476e8ae2cffd3dc98f105a
MD5 be1123dd7123e69ee8c271251abccfc0
BLAKE2b-256 d09fd707857dea14263160187a49e6b7574bb097cbf6adf5c3781cb2308a07fe

See more details on using hashes here.

Supported by

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