SMTP Server Issue on EC2 Instance

Job ID: 39288712

Budget: $10 – $30 USD

Have some issue in developing a very simple smtp server in EC2 instance. Used basic code first to start.
Server Code:
from aiosmtpd.smtp import SMTP as SMTPServer
from aiosmtpd.controller import Controller
from aiosmtpd.handlers import AsyncMessage
from email.message import EmailMessage
import base64

# ? Define valid credentials
VALID_USERNAME = "adminEmail"
VALID_PASSWORD = "secret123"

class AuthHandler(AsyncMessage):
async def handle_message(self, message: EmailMessage):
print("✅ Authenticated Email Received:")
print(f"From: {message['From']}")
print(f"To: {message['To']}")
print(f"Subject: {message['Subject']}")
print("Body:\n", message.get_payload())
return '250 Message accepted'
class CustomSMTP(SMTPServer):
async def auth_PLAIN(self, server, args):
if not args:
await self.push('334') # ask client to send base64 string
args = (await self._reader.readline()).strip()
auth_decoded = base64.b64decode(args).decode()
_, username, password = auth_decoded.split('\x00')
if username == VALID_USERNAME and password == VALID_PASSWORD:
print("✅ AUTH successful:", username)
return True
else:
print("❌ AUTH failed:", username)
return False
class AuthController(Controller):
def factory(self):
return AuthSMTP(self.handler)

if __name__ == "__main__":
controller = Controller(AuthHandler(), hostname="0.0.0.0", port=1025)
controller.start()
print("? SMTP AUTH server running on port 1025 (user: admin / pass: secret)")
try:
while True:
pass
except KeyboardInterrupt:
controller.stop()


Sender Code:
import smtplib

FROM = "senderEmail"
TO = "receiverEmail"
SUBJECT = "Test Email with AUTH"
BODY = "This is a test message."
msg = f"Subject: {SUBJECT}\n\n{BODY}"
#. x.x.x.x is the server running ec2 instance ip4 public address
server = smtplib.SMTP("x.x.x.x", 1025)
server.ehlo()
server.connect("x.x.x.x", 1025)
#server.ehlo()
try:
server.login("admin", "secret123")
server.ehlo()
server.sendmail(FROM, TO, msg)
#with smtplib.SMTP("18.204.217.40", 1025) as server:
# server.login("adminEmail", "secret123")
# server.sendmail(FROM, TO, msg)
finally:
server.close()
print("? Email sent successfully.")


Error: smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.

Inbound and outbound ports are open for 1025.