Preface
Email was the Internet’s first killer app. One of the most frequently asked questions about Java is how to send email from a Java applet or application. While it’s certainly possible to write a Java program that uses sockets to communicate with mail servers, this requires detailed knowledge of some fairly complicated protocols, such as SMTP, POP, and IMAP. Just as the URL class makes interacting with HTTP servers a lot simpler than it would be with raw sockets, so too can a class library dedicated to handling email make writing email clients a lot simpler.
The JavaMail API is a standard extension to Java that provides a class library for email clients. It’s a required component of the Java Platform, Enterprise Edition. The JavaMail API can be implemented in pure Java using sockets and streams, and indeed Oracle’s reference implementation is so implemented. Programs use the JavaMail API to communicate with SMTP, POP, and IMAP servers to send and receive email. By taking advantage of this API, you can avoid focusing on the low-level protocol details and focus instead on what you want to say with the message. Custom providers can support the proprietary features of mail systems such as Gmail and Microsoft Exchange. You can even install providers that add support for NNTP, the protocol used to transport Usenet news.
There’s no limit to the uses Java programs have for the JavaMail API. Most obviously, you can write standard email clients such ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access