Sendmail blocking spam email id, ips with access database

www.lau‮rutt‬i.com
Sendmail blocking spam email id, ips with access database

To block spam email using sendmail and an access database, you will need to set up a mail filter that can check incoming email against the database and block or flag messages that match certain criteria.

One way to do this is to use the milter feature of sendmail, which allows you to write custom filters using the libmilter library. You can write a milter filter in any programming language that can use the libmilter library, such as C, C++, or Python.

Here is an example of a milter filter written in Python that uses an access database to block spam messages based on the sender's email address or IP address:

import pyodbc
import Milter

class BlockFilter(Milter.Base):
    def __init__(self):
        self.id = self.ip = None
        self.conn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\database.mdb;')

    def envfrom(self, mailfrom, *str):
        self.id = mailfrom
        return Milter.CONTINUE

    def envrcpt(self, to, *str):
        cur = self.conn.cursor()
        cur.execute("SELECT * FROM blocked WHERE email=?", self.id)
        row = cur.fetchone()
        if row:
            self.reject("550 Blocked sender")
            return Milter.REJECT
        else:
            return Milter.CONTINUE

    def close(self):
        self.conn.close()

if __name__ == "__main__":
    Milter.factory = BlockFilter
    Milter.runmilter("blockfilter", "inet:8888@localhost", timeout=600)

To use this filter with sendmail, you will need to configure sendmail to use the milter feature and specify the path to the filter program. You can do this by adding the following lines to the sendmail.mc file and rebuilding the sendmail configuration:

INPUT_MAIL_FILTER(`blockfilter', `S=inet:8888@localhost')
define(`confMILTER_MACROS_ENVFROM', `i')
define(`confMILTER_MACROS_CONNECT', `{client_addr}')

You will also need to install the pyodbc module and any other dependencies required by the filter.

Keep in mind that this is just one example of how to block spam using an access database and sendmail. There are many other approaches you can take, depending on your specific requirements and the tools and libraries available on your system.

Created Time:2017-10-30 14:27:18  Author:lautturi