| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| computing:mailserver-trixie [2026/05/31 04:46] – oemb1905 | computing:mailserver-trixie [2026/07/28 19:52] (current) – oemb1905 |
|---|
| ------------------------------------------- | ------------------------------------------- |
| |
| * [[https://nextcloud.haacksnetworking.org/index.php/s/s6wAL5p7jKHc9Db|Slides]] | * [[https://cloud.haacksnetworking.org/index.php/s/P255xsGX37We4BS|Slides]] |
| * [[https://content.haacksnetworking.org/w/nsMwnJhLnfMrs17W5cAdWg|SeaGL Presentation]] | * [[https://content.haacksnetworking.org/w/erLgeVDEdeUf84FXq2Xk4f|SeaGL Presentation]] |
| * [[https://tech.haacksnetworking.org/2025/06/10/your-email-your-rules-self-hosting-simplified/|Blog Post]] | * [[https://tech.haacksnetworking.org/2025/06/10/your-email-your-rules-self-hosting-simplified/|Blog Post]] |
| |
| </code> | </code> |
| |
| Similarly, for large IMAP folders, you also want to adjust IMAP's logic to provide 256k (vs. 64k) to each single IMAP command. Additionally, make sure that you raise simultaneous connections from a single IP to 25, 50, or more, so your client can handle more in parallel. Lastly, adjust the idle time notification as well for less latency and snappier results. The default is 2mins, but if this is your server only, you can safely go as low as 15s or 30s. This lowering not only helps Roundcube, but helps Delta Chat and other email clients as well. | Similarly, for large IMAP folders, you also want to adjust IMAP's logic to provide 256k (vs. 64k) to each single IMAP command. Additionally, make sure that you raise simultaneous connections from a single IP to 25, 50, or more, so your client can handle more in parallel. Lastly, adjust the idle time notification as well for less latency and snappier results. The default is 2mins, but if this is your server only, you can safely go as low as 15s or 30s. This lowering not only helps Roundcube, but helps Delta Chat and other email clients as well. Open up ''/etc/dovecot/conf.d/20-imap.conf'' and add the following towards the bottom: |
| |
| <code> | <code> |
| #spf incoming policy and recipient restrictions\ | #spf incoming policy and recipient restrictions\ |
| policyd-spf_time_limit = 3600\ | policyd-spf_time_limit = 3600\ |
| smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, check_policy_service unix:private/policyd-spf | smtpd_recipient_restrictions = |
| | permit_mynetworks, |
| | permit_sasl_authenticated, |
| | reject_unauth_destination, |
| | reject_non_fqdn_recipient, |
| | reject_unknown_recipient_domain, |
| | check_policy_service unix:private/policyd-spf |
| </code> | </code> |
| |
| reject_unauthenticated_sender_login_mismatch, | reject_unauthenticated_sender_login_mismatch, |
| reject_sender_login_mismatch, | reject_sender_login_mismatch, |
| | check_sender_access hash:/etc/postfix/sender_access, |
| permit | permit |
| </code> | </code> |
| | |
| | The sender_access file is super helpful for repeat offenders. Sure, you can also just blacklist those in sieve rules, but that means that they still arrive and fill up your Junk folder. In some cases, spammers will send 100s of the same message per day. In those cases, it is helpful to stop them at the gates with postfix's sender_access: |
| | |
| | nano /etc/postfix/sender_access |
| | <spam@domain.com REJECT> #block exact email |
| | <domain.com REJECT> #block all users @domain.com |
| | <.domain.com REJECT> #block all users @sub.domain.com |
| | sudo postmap /etc/postfix/sender_access |
| | sudo postfix reload |
| | sudo systemctl restart postfix |
| |
| Now that the SPF/recipient and PTRI am now going to set up the DKIM policy for incoming email but/and, I will also use the same package to cut a DKIM keypair for use with the server's outgoing email. First, I install the policy and add opendkim to the postfix group. | Now that the SPF/recipient and PTRI am now going to set up the DKIM policy for incoming email but/and, I will also use the same package to cut a DKIM keypair for use with the server's outgoing email. First, I install the policy and add opendkim to the postfix group. |
| } | } |
| # rule:[spamcheck] | # rule:[spamcheck] |
| if anyof (header :contains "x-spam-status" "Yes", header :contains "x-spam-flag" "YES", header :contains "x-spam-level" "*****") | if anyof (header :matches "x-spam-status" "Yes", header :contains "x-spam-flag" "YES", header :contains "x-spam-level" "*****") |
| { | { |
| fileinto "Junk"; | fileinto "Junk"; |
| -- -- -- -- Miscellaneous Issues -- -- -- -- | -- -- -- -- Miscellaneous Issues -- -- -- -- |
| |
| To test sieve logic and rules, download email (.eml) from Roundcube that did not behave as planned. Once you have the email, ''ssh'' into your mail server's simple unix user's mail directory and do the following: | To test sieve's logic and/or to test spamassassin's scoring, download email (.eml) from Roundcube that did not behave as planned. Once you have the email, ''ssh'' into your mail server's simple unix user's mail directory and do the following: |
| |
| | su - username |
| cd ~/sieve | cd ~/sieve |
| sieve-test -D -e roundcube.sieve Amazon3.eml | spamassassin -t -D < Amazon1.eml |
| | # this ^^ gives you the headers / spamassassin scores in stdout |
| | sieve-test -D -e roundcube.sieve Amazon3.eml |
| | # this ^^ tests your sieve logic to see if the email goes in ham or spam |
| |
| In the output that follows, look for something like this: | In the output that follows, look for something like the below. I put example output for each command above, respectively: |
| | |
| | <code> |
| | Content analysis details: (16.9 points, 5.0 required) |
| | |
| | pts rule name description |
| | ---- ---------------------- -------------------------------------------------- |
| | 0.8 DKIM_ADSP_ALL No valid author signature, domain signs all mail |
| | 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record |
| | -0.0 SPF_PASS SPF: sender matches SPF record |
| | 0.2 BAYES_999 BODY: Bayes spam probability is 99.9 to 100% |
| | [score: 1.0000] |
| | 3.5 BAYES_99 BODY: Bayes spam probability is 99 to 100% |
| | [score: 1.0000] |
| | 2.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail |
| | domains are different |
| | 2.1 HTML_IMAGE_ONLY_12 BODY: HTML: images with 800-1200 bytes of words |
| | 0.0 HTML_EXTRA_CLOSE BODY: HTML contains far too many close tags |
| | 0.1 MIME_HTML_ONLY BODY: Message only has text/html MIME parts |
| | 0.0 HTML_MESSAGE BODY: HTML included in message |
| | 2.0 RDNS_DYNAMIC Delivered to internal network by host with |
| | dynamic-looking rDNS |
| | 0.0 HTML_SHORT_LINK_IMG_2 HTML is very short with a linked image |
| | 3.6 HTML_TAG_BALANCE_CENTER Malformatted HTML |
| | 0.4 HTML_MIME_NO_HTML_TAG HTML-only message, but there is no HTML tag |
| | 1.0 GOOG_STO_IMG_HTML Apparently using google content hosting to avoid |
| | URIBL |
| | 1.2 DMARC_QUAR DMARC quarantine policy |
| | 0.0 T_REMOTE_IMAGE Message contains an external image |
| | </code> |
| |
| <code> | <code> |
| I rewrote the mail server tutorial for the presentation [[https://tech.haacksnetworking.org/2025/06/10/your-email-your-rules-self-hosting-simplified/|Your Email, Your Rules: Self-Hosting Simplified]]. The SeaGL presentation can be found [[https://pretalx.seagl.org/2025/talk/VLM7AS/|on their calendar]]. | I rewrote the mail server tutorial for the presentation [[https://tech.haacksnetworking.org/2025/06/10/your-email-your-rules-self-hosting-simplified/|Your Email, Your Rules: Self-Hosting Simplified]]. The SeaGL presentation can be found [[https://pretalx.seagl.org/2025/talk/VLM7AS/|on their calendar]]. |
| |
| --- //[[alerts@haacksnetworking.org|oemb1905]] 2026/05/31 04:46// | --- //[[alerts@haacksnetworking.org|oemb1905]] 2026/07/28 19:51// |