<commit_before>import os
import asyncio
import aiosmtplib
import configparser

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
config = os.path.join(BASE_DIR, 'config.ini')

with open(config, 'r') as f:
    config_string = '[default]\n' + f.read()

settings = configparser.ConfigParser()
settings.read_string(config_string)

server = settings.get('default', 'SERVER')
port = settings.get('default', 'PORT')
username = settings.get('default', 'USERNAME')
password = settings.get('default', 'PASSWORD')

loop = asyncio.get_event_loop()
smtp = aiosmtplib.SMTP(hostname=server, port=port, loop=loop, use_tls=False)


class Sendmail:

    def process_message(self, peer, mailfrom, rcpttos, data, **kws):
        loop.create_task(self.delivery(mailfrom, rcpttos, data))

    async def delivery(self, mailfrom, rcpttos, data):
        await smtp.connect()
        await smtp.ehlo()
        await smtp.starttls()
        await smtp.login(username, password)
        await smtp.sendmail(mailfrom, rcpttos, data)<commit_msg>added logging<commit_after>import os
import asyncio
import aiosmtplib
import configparser

from traceback import print_exc
from datetime import datetime as dt

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
config = os.path.join(BASE_DIR, 'config.ini')

with open(config, 'r') as f:
    config_string = '[default]\n' + f.read()

settings = configparser.ConfigParser()
settings.read_string(config_string)

server = settings.get('default', 'SERVER')
port = settings.get('default', 'PORT')
username = settings.get('default', 'USERNAME')
password = settings.get('default', 'PASSWORD')

loop = asyncio.get_event_loop()
smtp = aiosmtplib.SMTP(hostname=server, port=port, loop=loop, use_tls=False)


class Sendmail:

    def process_message(self, peer, mailfrom, rcpttos, data, **kws):
        print('{0}: Got a mail from {1}'.format(dt.now(), mailfrom))
        loop.create_task(self.delivery(mailfrom, rcpttos, data))

    async def delivery(self, mailfrom, rcpttos, data):
        try:
            await smtp.connect()
            await smtp.ehlo()
            await smtp.starttls()
            await smtp.login(username, password)
            await smtp.sendmail(mailfrom, rcpttos, data)
        except Exception as e:
            print_exc()
        else:
            print('{0}: Mail has been successfully sent to {1}'.format(dt.now(), rcpttos))
{'fraction_non_alphanumeric': 0.13201180936313792, 'fraction_numerical': 0.001687051876845213, 'mean_word_length': 4.046808510638298, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2901878', 'n_tokens_mistral': 770, 'n_tokens_neox': 781, 'n_words': 181}