2025-05-31 16:32:11 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
receiver="info@example.com"
|
2025-06-13 09:41:55 +01:00
|
|
|
EMAIL_SERVER="localhost" #"pymta.example.com" "localhost"
|
|
|
|
|
EMAIL_SERVER_auth="10.100.111.1" # IP for authenticated server ( not localhost), use your main interface ip
|
|
|
|
|
|
|
|
|
|
sender="test@example.com"
|
|
|
|
|
username="test@example.com"
|
|
|
|
|
password="ZjDvcjPSs-nwK2Ghj5vQY7L4LdmTpmn_AEZMokJTFS" # password you setup for the user!
|
2025-05-31 16:32:11 +01:00
|
|
|
domain="example.com"
|
|
|
|
|
body_content_file="@tests/email_body.txt"
|
|
|
|
|
SMTP_PORT=4025
|
2025-06-13 09:41:55 +01:00
|
|
|
SMTP_TLS_PORT=40465
|
|
|
|
|
cc_recipient="ccrecipient@example.com"
|
|
|
|
|
bcc_recipient="bccrecipient@example.com"
|
2025-05-31 16:32:11 +01:00
|
|
|
|
|
|
|
|
<<com
|
2025-06-13 09:41:55 +01:00
|
|
|
python -m email_server.cli_tools add-domain $domain
|
|
|
|
|
python -m email_server.cli_tools add-user $username $password $domain
|
|
|
|
|
python -m email_server.cli_tools add-ip 127.0.0.1 $domain
|
|
|
|
|
python -m email_server.cli_tools add-ip 213.249.224.235 $domain
|
|
|
|
|
python -m email_server.cli_tools generate-dkim $domain
|
|
|
|
|
python -m email_server.cli_tools add-custom-header $domain X-Auth-Token "abc123-example-auth"
|
|
|
|
|
python -m email_server.cli_tools add-custom-header $domain X-Server-ID "mail01.example.com"
|
2025-05-31 16:32:11 +01:00
|
|
|
|
|
|
|
|
# options to add CC and BCC recipients for swaks
|
|
|
|
|
--cc $cc_recipient
|
|
|
|
|
--bcc $bcc_recipient
|
|
|
|
|
|
|
|
|
|
swaks --to $receiver \
|
|
|
|
|
--from $sender \
|
2025-06-13 09:41:55 +01:00
|
|
|
--server $EMAIL_SERVER \
|
2025-05-31 16:32:11 +01:00
|
|
|
--port $SMTP_TLS_PORT \
|
|
|
|
|
--auth LOGIN \
|
2025-06-13 09:41:55 +01:00
|
|
|
--auth-user $username \
|
2025-05-31 16:32:11 +01:00
|
|
|
--auth-password $password \
|
|
|
|
|
--tls \
|
|
|
|
|
--header "Subject: TLS - Large body email" \
|
2025-06-13 09:41:55 +01:00
|
|
|
--body $body_content_file
|
|
|
|
|
# --attach @/home/nahaku/Documents/Projects/SMTP_Server/tests/email_body.txt
|
|
|
|
|
# --attach @/home/nahaku/Documents/Projects/SMTP_Server/tests/Hello.jpg
|
2025-05-31 16:32:11 +01:00
|
|
|
|
2025-06-13 09:41:55 +01:00
|
|
|
com
|
|
|
|
|
<<com
|
|
|
|
|
|
|
|
|
|
com
|
2025-05-31 16:32:11 +01:00
|
|
|
swaks --to $receiver \
|
|
|
|
|
--from $sender \
|
2025-06-13 09:41:55 +01:00
|
|
|
--server $EMAIL_SERVER \
|
2025-05-31 16:32:11 +01:00
|
|
|
--port $SMTP_PORT \
|
|
|
|
|
--auth LOGIN \
|
2025-06-13 09:41:55 +01:00
|
|
|
--auth-user $username \
|
2025-05-31 16:32:11 +01:00
|
|
|
--auth-password $password \
|
2025-06-13 09:41:55 +01:00
|
|
|
--data "Subject: SMTP - authenticated success\n\nThis is the message body."
|
2025-05-31 16:32:11 +01:00
|
|
|
|
2025-06-13 09:41:55 +01:00
|
|
|
# Test with Authentication TLS
|
2025-05-31 16:32:11 +01:00
|
|
|
swaks --to $receiver \
|
|
|
|
|
--from $sender \
|
2025-06-13 09:41:55 +01:00
|
|
|
--server $EMAIL_SERVER \
|
2025-05-31 16:32:11 +01:00
|
|
|
--port $SMTP_TLS_PORT \
|
|
|
|
|
--auth LOGIN \
|
2025-06-13 09:41:55 +01:00
|
|
|
--auth-user $username \
|
2025-05-31 16:32:11 +01:00
|
|
|
--auth-password $password \
|
|
|
|
|
--tls \
|
2025-06-13 09:41:55 +01:00
|
|
|
--header "Subject: TLS - authenticated success" \
|
|
|
|
|
--body "This is the message body with proper headers."
|
2025-05-31 16:32:11 +01:00
|
|
|
|
2025-06-13 09:41:55 +01:00
|
|
|
# Test TLS + authentication and IP whitelist
|
2025-05-31 16:32:11 +01:00
|
|
|
swaks --to $receiver \
|
|
|
|
|
--from $sender \
|
2025-06-13 09:41:55 +01:00
|
|
|
--server $EMAIL_SERVER_auth \
|
2025-05-31 16:32:11 +01:00
|
|
|
--port $SMTP_TLS_PORT \
|
2025-06-13 09:41:55 +01:00
|
|
|
--auth LOGIN \
|
|
|
|
|
--auth-user $username \
|
|
|
|
|
--auth-password $password \
|
2025-05-31 16:32:11 +01:00
|
|
|
--tls \
|
2025-06-13 09:41:55 +01:00
|
|
|
--data "Subject: TLS - auth + IP Whitelist \n\nTest TLS + authentication and IP whitelist"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test with IP authentication TLS
|
|
|
|
|
swaks --to $receiver \
|
|
|
|
|
--from $sender \
|
|
|
|
|
--server $EMAIL_SERVER_auth \
|
|
|
|
|
--port $SMTP_TLS_PORT \
|
|
|
|
|
--tls \
|
|
|
|
|
--data "Subject: TLS - IP Whitelist - no auth\n\nTest with IP authentication TLS"
|
|
|
|
|
|
|
|
|
|
# Test with IP authentication SMTP
|
|
|
|
|
swaks --to $receiver \
|
|
|
|
|
--from $sender \
|
|
|
|
|
--server $EMAIL_SERVER_auth \
|
|
|
|
|
--port $SMTP_PORT \
|
|
|
|
|
--data "Subject: SMTP - IP Whitelist - no auth\n\nTest with IP authentication SMTP"
|
|
|
|
|
|
2025-05-31 16:32:11 +01:00
|
|
|
|
2025-06-13 09:41:55 +01:00
|
|
|
<<com
|
|
|
|
|
com
|
|
|
|
|
# SMTP un-auth test "Email_server - no Whitelist - no auth"
|
2025-05-31 16:32:11 +01:00
|
|
|
swaks --to $receiver \
|
|
|
|
|
--from $sender \
|
2025-06-13 09:41:55 +01:00
|
|
|
--server $EMAIL_SERVER \
|
2025-05-31 16:32:11 +01:00
|
|
|
--port $SMTP_PORT \
|
2025-06-13 09:41:55 +01:00
|
|
|
--data "Subject: SMTP - no Whitelist - no auth\n\nSMTP un-auth test Email_server - no Whitelist - no auth."
|
|
|
|
|
|
|
|
|
|
# Test TLS un-auth test "Email_server - no Whitelist - no auth"
|
|
|
|
|
swaks --to $receiver \
|
|
|
|
|
--from $sender \
|
|
|
|
|
--server $EMAIL_SERVER \
|
|
|
|
|
--port $SMTP_TLS_PORT \
|
|
|
|
|
--tls \
|
|
|
|
|
--data "Subject: TLS - no Whitelist - no auth\n\nTest TLS un-auth test Email_server - no Whitelist - no auth"
|