Implementing an email server in java
Maybe look at Apache JAMES.
The Apache JAMES Project delivers a rich set of open source modules and libraries, written in Java, related to internet mail and news which build into an advanced enterprise mail server.
If you want to implement an email server (SMTP, IMAP, POP3) - there is already Apache JAMES. It's open-source, so you can look into its sources if you insist on making one.
If you want to just send emails, having an already installed SMTP server, then use Simple Java Mail or commons-email. Both sit on top of Jakarta Mail (previously JavaMail) and are very developer-friendly.
for SMTP subethasmtp rocks