If you want to implement an email server (SMTP, IMAP, POP3), Apache JAMES already exists. It is open source, so you can peek into its sources if you insist on building it.
If you want to simply send an email with the SMTP server already installed, use commons-email . It sits ontop JavaMail and is very developer friendly.
source share