Adding greylisting to QMT and Account verification using badmailto: Difference between pages

From QmailToaster
(Difference between pages)
Jump to navigation Jump to search
No edit summary
 
No edit summary
 
Line 1: Line 1:
[[User_Tips_%26_Tricks#Anti_Spam|Back]]
[[User_Tips_%26_Tricks#Anti_Spam|Back]]


Download and configure qmail-greyd*
===Account verification using badmailto===
# cd /var/qmail/bin
 
# wget http://thomas.mangin.me.uk/data/source/qmail-greyd ([[qmail-greyd|qmail-greyd]])
If you do not use a catchall account, then any incoming mail to an undefined account will be bounced or deleted, depending the CatchAll setting. However, if you choose to use a catchall account (for whatever reason), you can specify characteristics of invalid account names using entries in the [[badmailto]] control file to reject mail to invalid account names.
  # chmod +x qmail-greyd
 
# mkdir /var/qmail/grey
For instance, if none of your account names contain the dash (-) character, you can include the line
  # chown vpopmail.vchkpw /var/qmail/grey<br>
[-].*@mydomain\.com$
Add ,GREY=”" to /etc/tcprules.d/tcp.smtp
in your [[badmailto]] file. This will reject any account name containing a dash. In a similar fashion, if no account names contain a period (.), you could add that too:
# vi /etc/tcprules/tcp.smtp<span style="color:red">
  [-.].*@mydomain\.com$
  :allow,BADMIMETYPE="",BADLOADERTYPE="M",CHKUSER_RCPTLIMIT="100",CHKUSER_WRONGRCPTLIMIT="20",QMAILQUEUE="/var/qmail/bin/simscan",NOP0FCHECK="1",GREY=""</span>
 
Add GREYD paramater to /var/qmail/supervise/smtp/run
If none of the accounts in your domain contain numeric digits, you could add them as well:
# vi /var/qmail/supervise/smtp/run<span style="color:red">
  [-.0-9].*@mydomain\.com$
  #!/bin/sh<br>
 
  QMAILDUID=`id -u vpopmail`
Here's a brief explaination of what's going on in these examples:
  NOFILESGID=`id -g vpopmail`
* [] specifies a class of characters. Any character contained within the braces is a member of the class.
  MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`
* the period (.) is a metacharacter meaning: any character.
  BLACKLIST=`cat /var/qmail/control/blacklists`
* the asterisk (*) is a metacharacter meaning: any number (0-n) of the preceding specification (class or character).
  SMTPD="/var/qmail/bin/qmail-smtpd"
* thus, .* means any number of any characters.
  TCP_CDB="/etc/tcprules.d/tcp.smtp.cdb"
* the regular expression will match a substring of the email recipient's address, so a leading .* is not necessary.
  RBLSMTPD="/usr/bin/rblsmtpd"
* metacharacters lose their meaning (they're just normal characters) when included in a class specification.
  HOSTNAME=`hostname`
* if a dash (-) is included within a class specification ([]), it indicates a range of characters, unless it is the first character within the specification, when it is treated as a class member.
  VCHKPW="/home/vpopmail/bin/vchkpw"
* the last period (.) is escaped with a backslash (\) so it is treated as a period instead of its metacharacter value.
  REQUIRE_AUTH=0
* the dollar sign ($) is a metacharacter meaning: the end of the address line.
  GREYD="/var/qmail/bin/qmail-greyd"<br>
 
  exec /usr/bin/softlimit -m 27000000 \
Regular expresssions in the badmailto file can be a powerful tool to reduce spam when using a catchall account.
    /usr/bin/tcpserver -v -R -H -l $HOSTNAME -x $TCP_CDB -c "$MAXSMTPD" \
 
    -u "$QMAILDUID" -g "$NOFILESGID" 0 smtp \
For more information about regular expressions, <i>[http://www.oreilly.com/catalog/regex/ Mastering Regular Expressions]</i> is an excellent resource.
    $GREYD $RBLSMTPD $BLACKLIST $SMTPD $VCHKPW /bin/true 2>&1</span><br>
 
Rebuild  tcprules and restart qmail
==[[User Tips & Tricks]]==
# qmailctl cdb
# qmailctl stop && sleep 2 && qmailctl start<br>
<b>*</b>''Note, this method is deprecated, in favor of using [[Spamdyke | spamdyke]]''

Latest revision as of 11:06, 30 March 2024

Back

Account verification using badmailto

If you do not use a catchall account, then any incoming mail to an undefined account will be bounced or deleted, depending the CatchAll setting. However, if you choose to use a catchall account (for whatever reason), you can specify characteristics of invalid account names using entries in the badmailto control file to reject mail to invalid account names.

For instance, if none of your account names contain the dash (-) character, you can include the line

[-].*@mydomain\.com$

in your badmailto file. This will reject any account name containing a dash. In a similar fashion, if no account names contain a period (.), you could add that too:

[-.].*@mydomain\.com$

If none of the accounts in your domain contain numeric digits, you could add them as well:

[-.0-9].*@mydomain\.com$

Here's a brief explaination of what's going on in these examples:

  • [] specifies a class of characters. Any character contained within the braces is a member of the class.
  • the period (.) is a metacharacter meaning: any character.
  • the asterisk (*) is a metacharacter meaning: any number (0-n) of the preceding specification (class or character).
  • thus, .* means any number of any characters.
  • the regular expression will match a substring of the email recipient's address, so a leading .* is not necessary.
  • metacharacters lose their meaning (they're just normal characters) when included in a class specification.
  • if a dash (-) is included within a class specification ([]), it indicates a range of characters, unless it is the first character within the specification, when it is treated as a class member.
  • the last period (.) is escaped with a backslash (\) so it is treated as a period instead of its metacharacter value.
  • the dollar sign ($) is a metacharacter meaning: the end of the address line.

Regular expresssions in the badmailto file can be a powerful tool to reduce spam when using a catchall account.

For more information about regular expressions, Mastering Regular Expressions is an excellent resource.

User Tips & Tricks