Test Email Setup#
This guide shows how to test the email functionality of pylinkahead locally using a throwaway SMTP server.
Prerequisites#
You need to have pylinkahead installed
You need docker
Steps#
We run Mailpit as a local SMTP server which does not actually send the mails. See the Mailpit documentation for configuration options.
Create a docker compose file:
# ./docker-compose.yml services: mailpit: image: axllent/mailpit:v1.29 command: - "--smtp-tls-cert" - "sans:localhost" - "--smtp-tls-key" - "sans:localhost" ports: - 8025:8025 - 1025:1025 environment: MP_SMTP_REQUIRE_STARTTLS: true MP_SMTP_AUTH_ALLOW_INSECURE: 0 MP_SMTP_AUTH: "user1:password"
Start the SMTP server:
docker compose up -d
Configure pylinkahead, add an
[Email]section to your pylinkahead.ini:# ./pylinkahead.ini [Email] smtp_server=localhost smtp_starttls=yes smtp_tls_verify=no smtp_port=1025 smtp_username=user1 smtp_password=password smtp_timeout=1.0 from_address="Test" <test@example.com> bcc_append=logger@example.com
smtp_tls_verify=nodisables certificate verification – safe here because Mailpit runs locally with a self-signed certificate, but never use this in production.Run interactive tests from the python REPL. A successful call returns
Nonesilently; verify delivery in the next step.>>> from linkahead.utils.email import send_email >>> send_email(message="test", subject="subj", to="to@example.com", cc="cc@example.com", bcc="bcc@example.com")
Check that the mail arrived: browse to
http://localhost:8025.Finally, shut down Mailpit with
docker compose down. This also deletes all test mails.
If you’re interested in how to configure your LinkAhead server so that you can
use linkahead.utils.email to send mails, e.g., in your server-side scripts,
please check out the administration
guide.