How can my postfix/spamcop learn from Gmail 421 rejections?

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a number of vanity catch-all email domains. Back in the day, that was a good idea, and now it's too late to change for my friends and family.
I do not relay out, only serving incoming domains. Those incoming messages then get forwarded using mail aliases rules that each user locally configures. I am receiving mail and forwarding to user gmail inboxes using postfix. To make sure I filter out 90%+ of the spam, I run spamassassin with auto-update, as well as two RBL blocking lists and SPF records. Good mail does get through to Google, which is great!
Bad mail that still slips through the net ends up with a 421 temporary denial from Google. Typically Google will say "this is spam" or "this contains bad links" in the reject message, which is good as far as it goes, but I don't read the logs every hour and check every message.
Currently, I run a command that flushes the deferred queue once a day, so that I don't re-try the same spam too often. This is somewhat fragile, because a single message that arrives right before the flush, and then gets deferred once for some technical reason (TCP timeout etc) would also get deleted without delivery. Not great!
So, how can I go about training my spanassassin based on the messages received back from Google?
For now, I'm thinking of something that wakes up every 10 minutes, tails the mail.log file, and looks for 421 messages, extracts the message ID using regex, then runs postcat on that message, and feeds it to sa-learn for training.
First: Is something like this already available?
Second: Can you find anything wrong, missed assumption, etc, in my reasoning above that I should correct?
postfix
add a comment |Â
up vote
1
down vote
favorite
I have a number of vanity catch-all email domains. Back in the day, that was a good idea, and now it's too late to change for my friends and family.
I do not relay out, only serving incoming domains. Those incoming messages then get forwarded using mail aliases rules that each user locally configures. I am receiving mail and forwarding to user gmail inboxes using postfix. To make sure I filter out 90%+ of the spam, I run spamassassin with auto-update, as well as two RBL blocking lists and SPF records. Good mail does get through to Google, which is great!
Bad mail that still slips through the net ends up with a 421 temporary denial from Google. Typically Google will say "this is spam" or "this contains bad links" in the reject message, which is good as far as it goes, but I don't read the logs every hour and check every message.
Currently, I run a command that flushes the deferred queue once a day, so that I don't re-try the same spam too often. This is somewhat fragile, because a single message that arrives right before the flush, and then gets deferred once for some technical reason (TCP timeout etc) would also get deleted without delivery. Not great!
So, how can I go about training my spanassassin based on the messages received back from Google?
For now, I'm thinking of something that wakes up every 10 minutes, tails the mail.log file, and looks for 421 messages, extracts the message ID using regex, then runs postcat on that message, and feeds it to sa-learn for training.
First: Is something like this already available?
Second: Can you find anything wrong, missed assumption, etc, in my reasoning above that I should correct?
postfix
1
This is the kind of thing thatperl'sFile::Tailmodule is good for. use File::Tail to monitor mail.log for 421 codes on delivery to google. extract the queue-id andpostcat -bhthe deferred mail to/usr/bin/sa-learn --spam .... I usesa-hamandsa-spamaliases for training spamassasin (which i run fromamavisd-new)...note: postfix runs|aliases as user nobody by default, so you'll need a second alias file owned by the user you run spamassassin as (in my case, that's useramavis)
â cas
Aug 6 '16 at 6:19
alternatively, don't use an alias, runsa-learndirectly from the File::Tail monitoring script, and run that script with the same uid that you use to run spamassassin.
â cas
Aug 6 '16 at 6:23
btw, I also useformail(from theprocmailpackage) to stripResent-Frometc headers (I usually bounce spam that gets through my filters tosa-spam). so mysa-spamalias looks like this:sa-spam: "|/usr/bin/formail -I Resent-From -I Resent-Date -I Resent-Message-ID -I Resent-To -s | /usr/bin/sa-learn --spam --dbpath /var/lib/amavis/.spamassassin/"
â cas
Aug 6 '16 at 6:25
finally,File::Tailseemed appropriate for a quick answer I wrote last night. it's just pseudocode, but it's still a useful example: unix.stackexchange.com/a/301545/7696
â cas
Aug 6 '16 at 6:31
Thanks for the suggestions. It sounds like you're basically doing what I had come up with! (But as a persistent process.) I have written perl before, and there are other languages I'd probably use if that's the way I go. (Including C -- nothing wrong with that :-)
â Jon Watte
Aug 7 '16 at 4:35
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a number of vanity catch-all email domains. Back in the day, that was a good idea, and now it's too late to change for my friends and family.
I do not relay out, only serving incoming domains. Those incoming messages then get forwarded using mail aliases rules that each user locally configures. I am receiving mail and forwarding to user gmail inboxes using postfix. To make sure I filter out 90%+ of the spam, I run spamassassin with auto-update, as well as two RBL blocking lists and SPF records. Good mail does get through to Google, which is great!
Bad mail that still slips through the net ends up with a 421 temporary denial from Google. Typically Google will say "this is spam" or "this contains bad links" in the reject message, which is good as far as it goes, but I don't read the logs every hour and check every message.
Currently, I run a command that flushes the deferred queue once a day, so that I don't re-try the same spam too often. This is somewhat fragile, because a single message that arrives right before the flush, and then gets deferred once for some technical reason (TCP timeout etc) would also get deleted without delivery. Not great!
So, how can I go about training my spanassassin based on the messages received back from Google?
For now, I'm thinking of something that wakes up every 10 minutes, tails the mail.log file, and looks for 421 messages, extracts the message ID using regex, then runs postcat on that message, and feeds it to sa-learn for training.
First: Is something like this already available?
Second: Can you find anything wrong, missed assumption, etc, in my reasoning above that I should correct?
postfix
I have a number of vanity catch-all email domains. Back in the day, that was a good idea, and now it's too late to change for my friends and family.
I do not relay out, only serving incoming domains. Those incoming messages then get forwarded using mail aliases rules that each user locally configures. I am receiving mail and forwarding to user gmail inboxes using postfix. To make sure I filter out 90%+ of the spam, I run spamassassin with auto-update, as well as two RBL blocking lists and SPF records. Good mail does get through to Google, which is great!
Bad mail that still slips through the net ends up with a 421 temporary denial from Google. Typically Google will say "this is spam" or "this contains bad links" in the reject message, which is good as far as it goes, but I don't read the logs every hour and check every message.
Currently, I run a command that flushes the deferred queue once a day, so that I don't re-try the same spam too often. This is somewhat fragile, because a single message that arrives right before the flush, and then gets deferred once for some technical reason (TCP timeout etc) would also get deleted without delivery. Not great!
So, how can I go about training my spanassassin based on the messages received back from Google?
For now, I'm thinking of something that wakes up every 10 minutes, tails the mail.log file, and looks for 421 messages, extracts the message ID using regex, then runs postcat on that message, and feeds it to sa-learn for training.
First: Is something like this already available?
Second: Can you find anything wrong, missed assumption, etc, in my reasoning above that I should correct?
postfix
postfix
edited 7 mins ago
Rui F Ribeiro
37.4k1374118
37.4k1374118
asked Aug 5 '16 at 16:31
Jon Watte
10814
10814
1
This is the kind of thing thatperl'sFile::Tailmodule is good for. use File::Tail to monitor mail.log for 421 codes on delivery to google. extract the queue-id andpostcat -bhthe deferred mail to/usr/bin/sa-learn --spam .... I usesa-hamandsa-spamaliases for training spamassasin (which i run fromamavisd-new)...note: postfix runs|aliases as user nobody by default, so you'll need a second alias file owned by the user you run spamassassin as (in my case, that's useramavis)
â cas
Aug 6 '16 at 6:19
alternatively, don't use an alias, runsa-learndirectly from the File::Tail monitoring script, and run that script with the same uid that you use to run spamassassin.
â cas
Aug 6 '16 at 6:23
btw, I also useformail(from theprocmailpackage) to stripResent-Frometc headers (I usually bounce spam that gets through my filters tosa-spam). so mysa-spamalias looks like this:sa-spam: "|/usr/bin/formail -I Resent-From -I Resent-Date -I Resent-Message-ID -I Resent-To -s | /usr/bin/sa-learn --spam --dbpath /var/lib/amavis/.spamassassin/"
â cas
Aug 6 '16 at 6:25
finally,File::Tailseemed appropriate for a quick answer I wrote last night. it's just pseudocode, but it's still a useful example: unix.stackexchange.com/a/301545/7696
â cas
Aug 6 '16 at 6:31
Thanks for the suggestions. It sounds like you're basically doing what I had come up with! (But as a persistent process.) I have written perl before, and there are other languages I'd probably use if that's the way I go. (Including C -- nothing wrong with that :-)
â Jon Watte
Aug 7 '16 at 4:35
add a comment |Â
1
This is the kind of thing thatperl'sFile::Tailmodule is good for. use File::Tail to monitor mail.log for 421 codes on delivery to google. extract the queue-id andpostcat -bhthe deferred mail to/usr/bin/sa-learn --spam .... I usesa-hamandsa-spamaliases for training spamassasin (which i run fromamavisd-new)...note: postfix runs|aliases as user nobody by default, so you'll need a second alias file owned by the user you run spamassassin as (in my case, that's useramavis)
â cas
Aug 6 '16 at 6:19
alternatively, don't use an alias, runsa-learndirectly from the File::Tail monitoring script, and run that script with the same uid that you use to run spamassassin.
â cas
Aug 6 '16 at 6:23
btw, I also useformail(from theprocmailpackage) to stripResent-Frometc headers (I usually bounce spam that gets through my filters tosa-spam). so mysa-spamalias looks like this:sa-spam: "|/usr/bin/formail -I Resent-From -I Resent-Date -I Resent-Message-ID -I Resent-To -s | /usr/bin/sa-learn --spam --dbpath /var/lib/amavis/.spamassassin/"
â cas
Aug 6 '16 at 6:25
finally,File::Tailseemed appropriate for a quick answer I wrote last night. it's just pseudocode, but it's still a useful example: unix.stackexchange.com/a/301545/7696
â cas
Aug 6 '16 at 6:31
Thanks for the suggestions. It sounds like you're basically doing what I had come up with! (But as a persistent process.) I have written perl before, and there are other languages I'd probably use if that's the way I go. (Including C -- nothing wrong with that :-)
â Jon Watte
Aug 7 '16 at 4:35
1
1
This is the kind of thing that
perl's File::Tail module is good for. use File::Tail to monitor mail.log for 421 codes on delivery to google. extract the queue-id and postcat -bh the deferred mail to /usr/bin/sa-learn --spam .... I use sa-ham and sa-spam aliases for training spamassasin (which i run from amavisd-new)...note: postfix runs | aliases as user nobody by default, so you'll need a second alias file owned by the user you run spamassassin as (in my case, that's user amavis)â cas
Aug 6 '16 at 6:19
This is the kind of thing that
perl's File::Tail module is good for. use File::Tail to monitor mail.log for 421 codes on delivery to google. extract the queue-id and postcat -bh the deferred mail to /usr/bin/sa-learn --spam .... I use sa-ham and sa-spam aliases for training spamassasin (which i run from amavisd-new)...note: postfix runs | aliases as user nobody by default, so you'll need a second alias file owned by the user you run spamassassin as (in my case, that's user amavis)â cas
Aug 6 '16 at 6:19
alternatively, don't use an alias, run
sa-learn directly from the File::Tail monitoring script, and run that script with the same uid that you use to run spamassassin.â cas
Aug 6 '16 at 6:23
alternatively, don't use an alias, run
sa-learn directly from the File::Tail monitoring script, and run that script with the same uid that you use to run spamassassin.â cas
Aug 6 '16 at 6:23
btw, I also use
formail (from the procmail package) to strip Resent-From etc headers (I usually bounce spam that gets through my filters to sa-spam). so my sa-spam alias looks like this: sa-spam: "|/usr/bin/formail -I Resent-From -I Resent-Date -I Resent-Message-ID -I Resent-To -s | /usr/bin/sa-learn --spam --dbpath /var/lib/amavis/.spamassassin/"â cas
Aug 6 '16 at 6:25
btw, I also use
formail (from the procmail package) to strip Resent-From etc headers (I usually bounce spam that gets through my filters to sa-spam). so my sa-spam alias looks like this: sa-spam: "|/usr/bin/formail -I Resent-From -I Resent-Date -I Resent-Message-ID -I Resent-To -s | /usr/bin/sa-learn --spam --dbpath /var/lib/amavis/.spamassassin/"â cas
Aug 6 '16 at 6:25
finally,
File::Tail seemed appropriate for a quick answer I wrote last night. it's just pseudocode, but it's still a useful example: unix.stackexchange.com/a/301545/7696â cas
Aug 6 '16 at 6:31
finally,
File::Tail seemed appropriate for a quick answer I wrote last night. it's just pseudocode, but it's still a useful example: unix.stackexchange.com/a/301545/7696â cas
Aug 6 '16 at 6:31
Thanks for the suggestions. It sounds like you're basically doing what I had come up with! (But as a persistent process.) I have written perl before, and there are other languages I'd probably use if that's the way I go. (Including C -- nothing wrong with that :-)
â Jon Watte
Aug 7 '16 at 4:35
Thanks for the suggestions. It sounds like you're basically doing what I had come up with! (But as a persistent process.) I have written perl before, and there are other languages I'd probably use if that's the way I go. (Including C -- nothing wrong with that :-)
â Jon Watte
Aug 7 '16 at 4:35
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f301563%2fhow-can-my-postfix-spamcop-learn-from-gmail-421-rejections%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
This is the kind of thing that
perl'sFile::Tailmodule is good for. use File::Tail to monitor mail.log for 421 codes on delivery to google. extract the queue-id andpostcat -bhthe deferred mail to/usr/bin/sa-learn --spam .... I usesa-hamandsa-spamaliases for training spamassasin (which i run fromamavisd-new)...note: postfix runs|aliases as user nobody by default, so you'll need a second alias file owned by the user you run spamassassin as (in my case, that's useramavis)â cas
Aug 6 '16 at 6:19
alternatively, don't use an alias, run
sa-learndirectly from the File::Tail monitoring script, and run that script with the same uid that you use to run spamassassin.â cas
Aug 6 '16 at 6:23
btw, I also use
formail(from theprocmailpackage) to stripResent-Frometc headers (I usually bounce spam that gets through my filters tosa-spam). so mysa-spamalias looks like this:sa-spam: "|/usr/bin/formail -I Resent-From -I Resent-Date -I Resent-Message-ID -I Resent-To -s | /usr/bin/sa-learn --spam --dbpath /var/lib/amavis/.spamassassin/"â cas
Aug 6 '16 at 6:25
finally,
File::Tailseemed appropriate for a quick answer I wrote last night. it's just pseudocode, but it's still a useful example: unix.stackexchange.com/a/301545/7696â cas
Aug 6 '16 at 6:31
Thanks for the suggestions. It sounds like you're basically doing what I had come up with! (But as a persistent process.) I have written perl before, and there are other languages I'd probably use if that's the way I go. (Including C -- nothing wrong with that :-)
â Jon Watte
Aug 7 '16 at 4:35