A sendmail
that forwards incoming mail as an attachment to a single receiver, through a single relay host.
This tool is for use on systems that aren't supposed to send mail to actual users, but, where system daemons (smartmontools, cron) etc occasionally send email that an admin should see.
Many people seem to address this use case with nullmailer
/ ssmtp
/ msmtp
/ dma
.
However, I found that many relay hosts put requirements on {envelope,header}x{from,to}
.
For example, I found it tricky to impossible to configure above tools to relay through AWS SES, where the IAM user is restricted by various policies to certain sender & receiver addresses.
To comply, one would need to configure above tools to rewrite {envelope,header}x{from,to}
.
However, I found that hard or impossible to do, especially if the recipient address is restricted by the relayhost policy.
Hence, I wrote this tiny sendmail
replacement.
Deploy it to your Debian using the instructions below.
Here's how the received message look like in Mutt and Apple Mail. We use inline attachments for convenience in the GUI.
![screenshot mutt](https://private-user-images.githubusercontent.com/956573/300649704-592247c9-9da0-41c2-ac19-4895a9014101.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMzg5MTUsIm5iZiI6MTcyNDAzODYxNSwicGF0aCI6Ii85NTY1NzMvMzAwNjQ5NzA0LTU5MjI0N2M5LTlkYTAtNDFjMi1hYzE5LTQ4OTVhOTAxNDEwMS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxOVQwMzM2NTVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hZTQ2ZjhjNWYxNzI4YjM0NDc4YWY4NTNlNjNiNzFmZDdlZDFiMmZjMjdjM2RlYzM0ZTA1ODIyNmIyN2ZhYWIxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.q6aIZUo-mOfhkdN06IpmAgh4hCNSiOZF7CPV6Nn1Jpc)
![screenshot](https://private-user-images.githubusercontent.com/956573/300649206-ebf25b7f-ea5f-4fa4-b9a5-66373063d68c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMzg5MTUsIm5iZiI6MTcyNDAzODYxNSwicGF0aCI6Ii85NTY1NzMvMzAwNjQ5MjA2LWViZjI1YjdmLWVhNWYtNGZhNC1iOWE1LTY2MzczMDYzZDY4Yy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxOVQwMzM2NTVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mMDBiNDk1MzJhNzMwZmVjNmUyNDJmZDMwZmNjY2U2YjJlNDZmYzNmOTEzYjJhYmNkNTBjZGRlOGI1M2FkY2I4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.Xmi_6EjVShq6Wnsc9uiW6vqSyBiOf5_9ACza41c_GMU)
Install cargo deb
.
Then
# build debian package
cargo deb --target x86_64-unknown-linux-musl
# list built debian package's contents
dpkg-deb -c target/x86_64-unknown-linux-musl/debian/forward-as-attachment-mta_0.1.0-1_amd64.deb
Install above .deb
on your system.
The create the config file:
# /etc/forward-as-attachment-mta.config.toml
sender_email = "notifications@example.com"
recipient_email= "notifications@example.com"
smtp_host= "email-smtp.eu-central-1.amazonaws.com"
smtp_username= "..."
smtp_password= "..."
See GitHub releases.
version=0.2.1
gsed -i -E 's/^version =.*/version = "'"$version"'"/' Cargo.toml
git add Cargo.toml
git commit -m "$version"
cargo deb --target x86_64-unknown-linux-musl
gh release create v$version --generate-notes ./target/x86_64-unknown-linux-musl/debian/forward-as-attachment-mta_$version-1_amd64.deb