Last active
December 2, 2024 10:55
-
-
Save abelevtsov/3991f53590693878a4f72d896341f0a0 to your computer and use it in GitHub Desktop.
port25 PowerMTA bounce accounting with send to MongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DEFAULT] | |
[headers] | |
headers = type,timeLogged,timeQueued,orig,rcpt,orcpt,dsnAction,dsnStatus,dsnDiag,dsnMta,bounceCat,srcType,srcMta,dlvType,dlvSourceIp,dlvDestinationIp,dlvEsmtpAvailable,dlvSize,vmta,jobId,envId,queue,vmtaPool | |
[mongo] | |
host = 127.0.0.1 | |
port = 27017 | |
queueName = pmta-events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import datetime | |
import configparser | |
import pymongo | |
import csv | |
import io | |
config = configparser.ConfigParser() | |
config.read("./bounce.conf") | |
# read accounting headers | |
headers = config.get("headers", "headers") | |
keys = ("_t," + headers).split(",") | |
# read mongo config | |
mongoSection = config["mongo"] | |
host = mongoSection.get("host") | |
port = mongoSection.getint("port") | |
queueName = mongoSection.get("queueName") | |
# connect to mongo | |
try: | |
c = pymongo.MongoClient(host, port) | |
except ConnectionFailure, e: | |
sys.stderr.write("Could not connect to MongoDB: %s" % e) | |
sys.exit(1) | |
db = c.Scheduler | |
queue = db.Queue | |
# read first line - unused | |
line = sys.stdin.readline() | |
while line: | |
line = sys.stdin.readline() | |
if line: | |
# write accounting data to queue | |
values = list(csv.reader(io.StringIO('EmailStatusReceived,' + line)))[0] | |
message = dict(zip(keys, values)) | |
queue.insert({ | |
"QueueName": queueName, | |
"Message": message, | |
"NextVisibleTime": datetime.datetime.utcnow(), | |
"DequeueCount": 0 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
๐๐๐Get latest-version powermta and other marketing tools with lifetime license key and support from me๐๐๐
contact on:
skype: salimrezabd04
telegram: salimrezabd1
telegram: salimrezabd