Part I Development Tasks and Tools
1. Setting Up a Development Environment
Part II Developing Applications and Application Components
6. Using the Java Persistence API
7. Developing Web Applications
8. Using Enterprise JavaBeans Technology
9. Using Container-Managed Persistence
12. Developing Lifecycle Listeners
13. Developing OSGi-enabled Java EE Applications
Part III Using Services and APIs
14. Using the JDBC API for Database Access
15. Using the Transaction Service
16. Using the Java Naming and Directory Interface
17. Using the Java Message Service
The following topics are addressed here:
import java.util.*; import javax.activation.*; import javax.mail.*; import javax.mail.internet.*; import javax.naming.*;
InitialContext ic = new InitialContext(); String snName = "java:comp/env/mail/MyMailSession"; Session session = (Session)ic.lookup(snName);
For more information, see Looking Up a JavaMail Session.
For example:
Properties props = session.getProperties(); props.put("mail.from", "user2@mailserver.com");
The msgRecipient, msgSubject, and msgTxt variables in the following example contain input from the user:
Message msg = new MimeMessage(session); msg.setSubject(msgSubject); msg.setSentDate(new Date()); msg.setFrom(); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(msgRecipient, false)); msg.setText(msgTxt);
Transport.send(msg);
import java.util.*; import javax.activation.*; import javax.mail.*; import javax.mail.internet.*; import javax.naming.*;
InitialContext ic = new InitialContext(); String snName = "java:comp/env/mail/MyMailSession"; Session session = (javax.mail.Session)ic.lookup(snName);
For more information, see Looking Up a JavaMail Session.
For example:
Properties props = session.getProperties(); props.put("mail.from", "user2@mailserver.com");
You must supply a mail server name, a mail user name, and a password.
Store store = session.getStore(); store.connect("MailServer", "MailUser", "secret");
Folder folder = store.getFolder("INBOX");
Message[] messages = folder.getMessages();