diff --git a/CNP/Wireshark/SMTP/mail-sender.py b/CNP/Wireshark/SMTP/mail-sender.py new file mode 100644 index 0000000..186f05e --- /dev/null +++ b/CNP/Wireshark/SMTP/mail-sender.py @@ -0,0 +1,14 @@ +import smtplib +from email.message import EmailMessage + +# the email message +msg = EmailMessage() +msg['Subject'] = 'CNP Assignment Email' +msg['From'] = 'aadit@example.com' +msg['To'] = 'shreyas@example.com' # used example.com just to not have a DNS error. +msg.set_content('Hello World. This is a message that is to be captured for the CNP FISAC II.') + +#SMTP server running on localhost on port 25 +with smtplib.SMTP('127.0.0.1', 25) as server: + server.set_debuglevel(1) # debug output to see the SMTP conversation (for dev log) + server.send_message(msg) diff --git a/CNP/Wireshark/SMTP/smtp-server.py b/CNP/Wireshark/SMTP/smtp-server.py new file mode 100644 index 0000000..1868743 --- /dev/null +++ b/CNP/Wireshark/SMTP/smtp-server.py @@ -0,0 +1,33 @@ +import asyncio +import uvloop +from aiosmtpd.controller import Controller + +# handler that just prints the message content +class PrintHandler: + async def handle_DATA(self, server, session, envelope): + print("Message from:", envelope.mail_from) + print("Recipients:", envelope.rcpt_tos) + print("Message data:") + print(envelope.content.decode('utf8', errors='replace')) + print("End of message") + # Respond with a success code + return '250 Message accepted for delivery' + +# uvloop for better performance +asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) + +def run_server(): + # SMTP server controller, binding to localhost on port 25 + controller = Controller(PrintHandler(), hostname='127.0.0.1', port=25) + controller.start() + print("SMTP server running on port 25. Press Ctrl+C to stop.") + try: + # Run forever + asyncio.get_event_loop().run_forever() + except KeyboardInterrupt: + pass + finally: + controller.stop() + +if __name__ == '__main__': + run_server()