Okay. So here is all information. Hopefully someone can see what's going wrong.
Regards, Rene -------------------------------------------------------------------------------------- The code of MyMilter: -------------------------------------------------------------------------------------- class MyMilter(ppymilterbase.PpyMilter): auth_name = None def __init__(self): ppymilterbase.PpyMilter.__init__(self) def OnMacro(self, cmd, macro_cmd, data): if(macro_cmd=='M'): try: self.auth_name = data[data.index('{auth_authen}')+1] except ValueError: pass return self.Continue() def OnMailFrom(self, cmd, mail_from, esmtp_info): if(self.auth_name): cursor.execute("SELECT day_limit FROM `accounting`, `mailboxes` WHERE\ `accounting`.`email` = `mailboxes`.`email`\ AND `accounting`.`email` = '"+self.auth_name+"'\ AND `accounting`.`date` = CURDATE()\ AND `accounting`.`counter` >= `mailboxes`.`day_limit`") result = cursor.fetchall() if(len(result)): return self.CustomReply('554', '5.7.1 Mail limit reached') return self.Continue() def OnEndBody(self, cmd): if(self.auth_name): cursor.execute("INSERT INTO accounting (`email`,`date`,`counter`) VALUES ('"+self.auth_name+"', CURDATE(), 1)\ ON DUPLICATE KEY UPDATE counter=counter+1") return self.Continue() def OnResetState(self): self.auth_name=None -------------------------------------------------------------------------------------- WORKING ITEM -------------------------------------------------------------------------------------- Milter log: -------------------------------------------------------------------------------------- DEBUG:root: <<< O=00=00=00=06=00=00=01=FF=00=1F=FF=FF DEBUG:root:RESPONSE: O{ DEBUG:root: >>> O DEBUG:root: <<< DCj=00mail.sender.com=00{daemon_name}=00mail.sender.com=00v=00Postfix 2.6.6= =00 DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< DH DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< DM{auth_type}=00LOGIN=00{auth_authen}=00r...@sender.com=00{mail_addr}=00rene= @sender.com=00{mail_host}=00sender.com=00{mail_mailer}=00virtual=00 DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< M<r...@sender.com>=00 DEBUG:root:RESPONSE: y554 5.7.1 Mail limit reached DEBUG:root: >>> y DEBUG:root: <<< DR{rcpt_addr}=00u...@receiver.com=00{rcpt_host}=00receiver.com=00{rcpt_mailer}= =00smtp=00 DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< DTi=001D3435D0=00 DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< T ERROR:root:No parser implemented for "Data" DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< DEi=001D3435D0=00 DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< E DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< A DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< A DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< Q INFO:root:Closing connection ("received quit command") -------------------------------------------------------------------------------------- maillog -------------------------------------------------------------------------------------- Jul 12 14:16:49 mail postfix/smtpd[3650]: connect from xxxxxxx[xx.xx.xx.xx] Jul 12 14:16:49 mail postfix/smtpd[3650]: 1D3435D0: client=xxxxxxx[xx.xx.xx.xx], sasl_method=LOGIN, sasl_username=r...@sender.com Jul 12 14:16:49 mail postfix/cleanup[3659]: 1D3435D0: message-id=<011701cd6028$5a27d290$0e7777b0$@sender.com> Jul 12 14:16:49 mail postfix/cleanup[3659]: 1D3435D0: milter-reject: END-OF-MESSAGE from xxxxxxx[xx.xx.xx.xx]: 5.7.1 Mail limit reached; from=<r...@sender.com> to=<u...@receiver.com> proto=ESMTP helo=<ReneWin8> Jul 12 14:16:51 mail postfix/smtpd[3650]: disconnect from xxxxxxx[xx.xx.xx.xx] -------------------------------------------------------------------------------------- NON WORKING ITEM -------------------------------------------------------------------------------------- Milter log: -------------------------------------------------------------------------------------- DEBUG:root: <<< O=00=00=00=06=00=00=01=FF=00=1F=FF=FF DEBUG:root:RESPONSE: O{ DEBUG:root: >>> O DEBUG:root: <<< DCj=00mail.sender.com=00{daemon_name}=00mail.sender.com=00v=00Postfix 2.6.6= =00 DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< DH DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< DM{auth_type}=00LOGIN=00{auth_authen}=00r...@sender.com=00{mail_addr}=00rene= @sender.com=00{mail_host}=00sender.com=00{mail_mailer}=00virtual=00 DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< M<r...@sender.com>=00 DEBUG:root:RESPONSE: y554 5.7.1 Mail limit reached DEBUG:root: >>> y DEBUG:root: <<< DR{rcpt_addr}=00u...@receiver.com=00{rcpt_host}=00receiver.com=00{rcpt_mailer}= =00smtp=00 DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< DTi=0053F9F5D0=00 DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< T ERROR:root:No parser implemented for "Data" DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< DEi=0053F9F5D0=00 DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< E DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< A DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< A DEBUG:root:RESPONSE: c DEBUG:root: >>> c DEBUG:root: <<< Q -------------------------------------------------------------------------------------- maillog -------------------------------------------------------------------------------------- Jul 12 14:20:35 mail postfix/smtpd[3814]: connect from xxxxxxx[xx.xx.xx.xx] Jul 12 14:20:35 mail postfix/smtpd[3814]: 53F9F5D0: client=xxxxxxx[xx.xx.xx.xx], sasl_method=LOGIN, sasl_username=r...@sender.com Jul 12 14:20:35 mail postfix/cleanup[3823]: 53F9F5D0: message-id=<016b01cd6028$e0feb680$a2fc2380$@sender.com> Jul 12 14:20:35 mail postfix/qmgr[2970]: 53F9F5D0: from=<r...@sender.com>, size=2789, nrcpt=1 (queue active) Jul 12 14:20:35 mail postfix/pickup[3624]: 7EDEC2B58: uid=498 from=<r...@sender.com> Jul 12 14:20:35 mail postfix/cleanup[3823]: 7EDEC2B58: message-id=<016b01cd6028$e0feb680$a2fc2380$@sender.com> Jul 12 14:20:35 mail postfix/qmgr[2970]: 7EDEC2B58: from=<r...@sender.com>, size=3118, nrcpt=1 (queue active) Jul 12 14:20:35 mail postfix/pipe[3846]: 53F9F5D0: to=<u...@receiver.com>, relay=dfilt, delay=0.22, delays=0.14/0.01/0/0.07, dsn=2.0.0, status=sent (delivered via dfilt service) Jul 12 14:20:35 mail postfix/qmgr[2970]: 53F9F5D0: removed Jul 12 14:20:35 mail postfix/smtp[3855]: 7EDEC2B58: to=<u...@receiver.com>, relay=mx1.receiver.com[xx.xx.xx.xx]:25, delay=0.17, delays=0.01/0.01/0.09/0.06, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 4C8ECA92B7C) Jul 12 14:20:35 mail postfix/qmgr[2970]: 7EDEC2B58: removed Jul 12 14:20:37 mail postfix/smtpd[3814]: disconnect from xxxxxxx[xx.xx.xx.xx] -------------------------------------------------------------------------------------- postconf -n -------------------------------------------------------------------------------------- alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases broken_sasl_auth_clients = yes command_directory = /usr/sbin config_directory = /etc/postfix daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix debug_peer_level = 2 html_directory = no inet_interfaces = all inet_protocols = all mail_owner = postfix mailq_path = /usr/bin/mailq.postfix manpage_directory = /usr/share/man mydestination = mail.sender.com, localhost, localhost.localdomain myhostname = mail.sender.com mynetworks = 127.0.0.0/8,82.94.217.29 newaliases_path = /usr/bin/newaliases.postfix proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps queue_directory = /var/spool/postfix readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES sample_directory = /usr/share/doc/postfix-2.6.6/samples sendmail_path = /usr/sbin/sendmail.postfix setgid_group = postdrop smtpd_end_of_data_restrictions = smtpd_milters = inet:localhost:12345 smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination smtpd_sasl_auth_enable = yes smtpd_sasl_authenticated_header = yes smtpd_tls_cert_file = /etc/postfix/cert.crt smtpd_tls_key_file = /etc/postfix/cert.key smtpd_use_tls = yes transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf unknown_local_recipient_reject_code = 550 virtual_alias_domains = virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf virtual_gid_maps = static:5000 virtual_mailbox_base = /home/vmail virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf virtual_mailbox_limit_override = yes virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf virtual_maildir_extended = yes virtual_maildir_limit_message = "The user you are trying to reach is over quota." virtual_overquota_bounce = yes virtual_uid_maps = static:5000 ________________________________________ Van: wie...@porcupine.org [wie...@porcupine.org] Verzonden: donderdag 12 juli 2012 12:54 Aan: René Klomp CC: postfix-users@postfix.org Onderwerp: Re: Milter reply Ren? Klomp: > I am trying to create a milter (in python with ppymilter) for > postfix to allow users to send only a specific amount of emails > per day. > > In the OnEndBody function I increment a counter field in my database > and in OnMailFrom I read the field and if it is bigger than the > daily limit I will return self.CustomReply('554', '5.7.1 Mail limit > reached') > > In my debug log I can see that the milter sends "y554 5.7.1 Mail > limit reached" to postfix in reply of "M<mailadres>". So to me > it looks like the milter is working correct, but postfix does not > always give a error code. Half of the mails is just accepted and > delivered. > > Is this a bug in my milter or in postfix? Can it be solved? What is the output of the command "postconf -n". What is the logging for "good" and "bad" mail handling. See the mailing list welcome message for further instructions. Wietse