Версия: 0.1.0

asyncio
inpos 2016-05-25 18:30:12 +03:00
parent 9b3980289b
commit 451ca04d4b
2 changed files with 40 additions and 3 deletions

View File

@ -3,12 +3,12 @@ class Config(object):
pass pass
conf = Config() conf = Config()
conf.VERSION = '0.0.1' conf.VERSION = '0.1.0'
conf.SRVNAME = 'Serpent' conf.SRVNAME = 'Serpent'
conf.srv_version = '%s %s' % (conf.SRVNAME, conf.VERSION) conf.srv_version = '%s %s' % (conf.SRVNAME, conf.VERSION)
conf.local_domains = ['dom.lan'] # Список доменов, для которых будет приниматься почта conf.local_domains = ['dom.lan'] # Список доменов, для которых будет приниматься почта
conf.tls = True conf.tls = True
conf.tls_pem = '/home/inpos/Программы/git/pydev/serpent/serpent.pem' conf.tls_pem = './serpent.pem'
conf.smtp_open_relay = False # Разрешить ли пересылку откуда угодно куда угодно conf.smtp_open_relay = False # Разрешить ли пересылку откуда угодно куда угодно
conf.smtp_email_delim = '@' conf.smtp_email_delim = '@'
conf.smtp_header = '''from [{sender_ip}] (helo={sender_host}) conf.smtp_header = '''from [{sender_ip}] (helo={sender_host})
@ -24,6 +24,7 @@ conf.smtp_message_size = 40 # Размер в МБ
conf.smtp_queue_check_period = 30 # Период запуска обработки очереди в минутах conf.smtp_queue_check_period = 30 # Период запуска обработки очереди в минутах
conf.smtp_queue_message_ttl = 3 * 24 * 60 # Время жизни сообщения в очереди в минутах conf.smtp_queue_message_ttl = 3 * 24 * 60 # Время жизни сообщения в очереди в минутах
conf.maildir_user_path = 'mailstore/%s/' conf.maildir_user_path = 'mailstore/%s/'
conf.smtp_email_tls_required = True
conf.imap_SENT = 'Sent' conf.imap_SENT = 'Sent'
conf.imap_TRASH = 'Trash' conf.imap_TRASH = 'Trash'

View File

@ -3,6 +3,9 @@ from serpent.config import conf
from serpent import dataio, misc, rules from serpent import dataio, misc, rules
from datetime import datetime, timedelta from datetime import datetime, timedelta
from os import path from os import path
from DNS import dnslookup
from operator import itemgetter
from smtplib import SMTP
class SmtpQueue(object): class SmtpQueue(object):
def __init__(self, store, local_delivery): def __init__(self, store, local_delivery):
@ -39,7 +42,40 @@ class SmtpQueue(object):
return self.local_delivery.deliver(user, message['message']) return self.local_delivery.deliver(user, message['message'])
def __send_email_(self, mid): def __send_email_(self, mid):
pass info = self.stor.getinfo(mid)
try:
mail_servers = dnslookup(info['rcpt'][1], 'mx')
except:
return False
mail_servers = sorted(mail_servers, key=itemgetter(0))
for _, mx in mail_servers:
s = SMTP(local_hostname = conf.smtp_hostname)
try:
ret_code, banner = s.connect(mx, 25)
except:
s.quit()
continue
if ret_code != 220:
s.quit()
continue
try:
s.starttls()
except:
if conf.smtp_email_tls_required:
s.quit()
continue
from_addr = conf.smtp_email_delim.join(info['from'])
to_addr = conf.smtp_email_delim.join(info['rcpt'])
message = self.stor.read(mid)
try:
s.sendmail(from_addr, [to_addr], message['message'])
except:
s.quit()
continue
s.quit()
return True
return False
def __freeze_(self, mid): def __freeze_(self, mid):
info = self.stor.getinfo(mid) info = self.stor.getinfo(mid)