This commit is contained in:
huangzhenpc
2025-02-27 09:27:44 +08:00
parent 064b44c3b3
commit c158e42ded

View File

@@ -30,6 +30,9 @@ class CustomSMTPServer(smtpd.SMTPServer):
logger.info(f"Initializing SMTP server on {localaddr}")
super().__init__(localaddr, remoteaddr)
# 定义允许的域名列表
ALLOWED_DOMAINS = ['nosqli.com', 'email.nosqli.com']
def process_message(self, peer, mailfrom, rcpttos, data, **kwargs):
try:
logger.debug(f"Connection from peer: {peer}")
@@ -44,7 +47,8 @@ class CustomSMTPServer(smtpd.SMTPServer):
# 验证收件人域名
valid_recipients = []
for rcpt in rcpttos:
if not rcpt.endswith('@nosqli.com'):
is_valid = any(rcpt.endswith(f'@{domain}') for domain in self.ALLOWED_DOMAINS)
if not is_valid:
logger.warning(f"Rejected mail to {rcpt}: invalid domain")
else:
valid_recipients.append(rcpt)