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

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question



















  • 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











  • 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











  • 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














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?










share|improve this question



















  • 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











  • 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











  • 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












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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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










  • 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










  • 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




    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










  • 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










  • 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















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

Peggy Mitchell

The Forum (Inglewood, California)

Palaiologos