Test Email Setup#
Note
This new page has not yet been fully revised. There might be inconsistencies or errors when using with current LinkAhead versions.
Overview#
We will
Start an SMTP server which will receive our emails.
Run tests from the command line.
Prerequisites#
You need to have pylinkahead installed
You need docker
Steps#
We run Mailpit as a local SMTP server which does actually send the mails.
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_REQUIRE_TLS: true #MP_SMTP_AUTH_ACCEPT_ANY: 1 MP_SMTP_AUTH_ALLOW_INSECURE: 0 MP_SMTP_AUTH: "user1:password"
Start the STMP 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
Run interactive tests from the python REPL:
>>> 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 mails, browse to
http://localhost:8025.Finally, shut down Mailpit with
docker compose down. This also deletes all test mails.