-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change default setting for server to support all incoming mail.
Close #2
- Loading branch information
Showing
3 changed files
with
34 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
import logging | ||
|
||
from aiosmtpd.smtp import Envelope, Session, SMTP | ||
|
||
|
||
log = logging.getLogger("smtphandler") | ||
|
||
|
||
class ExampleHandler: | ||
async def handle_RCPT(self, | ||
server: SMTP, | ||
session: Session, | ||
envelope: Envelope, | ||
address: str, | ||
rcpt_options: list): | ||
if not address.endswith('@example.com'): | ||
return '550 not relaying to that domain' | ||
# Accept all incoming mail for now | ||
# if not address.endswith('@example.com'): | ||
# return '550 not relaying to that domain' | ||
log.info("Handle RCPT for %s", address) | ||
envelope.rcpt_tos.append(address) | ||
return '250 OK' | ||
|
||
async def handle_DATA(self, | ||
server: SMTP, | ||
session: Session, | ||
envelop: Envelope): | ||
content = envelop.content.decode("utf8", errors="replace") | ||
print(f'Message from {envelop.mail_from}') | ||
print(f'Message for {envelop.rcpt_tos}') | ||
print(f'Message data:\n{content}') | ||
print('End of message') | ||
content = envelop.content | ||
log.debug('Message from %s', envelop.mail_from) | ||
log.debug('Message for %s', envelop.rcpt_tos) | ||
log.debug('Message data:\n%s\n%s', content, '*'*20) | ||
return '250 Message accepted for delivery' |