JSP and Java Mail API

xiaoxiao2021-03-06  168

JSP and Java Mail API

Summary: The development of Java Mail API is a good example of sustaining efforts to provide a public API framework for Java developers. Promote a public framework, opposing a resolution of the supplier, fully predicting an increasingly open development environment. The structure of the Java Mail API itself proves that one of its developers - the workload of software development should depend on the complexity of the application itself and the degree of control required by the developer. In other words, Java Mail APIs are as simple as possible. At first glance, the total number of classes and classes between Java Mail APIs may make people misunderstand long learning time. In fact, once it is officially started, you will find that the API does not loses a simple tool to join a robust mail / communication support in the application. Establish a JavaMail use environment, which software needs to first, you need to install the JavaMail API. There are now two commonly used JavaMail API versions: 1.2 and 1.1.3. Although version 1.2 is the latest version, version 1.1.3 contains version 1.2.1 of Java 2 Platform, Enterprise Edition, J2EE, so many people still use it. · JavaMail 1.2 installation To use JavaMail 1.2 API, download the JavaMail 1.2 implementation, unpack the javamail-1_2.zip file, and add the mail.jar file to the classpath. In addition to the core class, with version 1.2 implementation, SMTP, IMAP4, and POP3 suppliers are available. · JavaMail 1.1.3 installation To use JavaMail 1.1.3 API, download the JavaMail 1.1.3 implementation, unwield the javamail1_1_3.zip file, and add the mail.jar file to your classpath. In addition to the core class, the SMTP and IMAP4 suppliers are available with the version 1.1.3 implementation. If you access a POP server with JavaMail 1.1.3, download and install a POP3 vendor. Sun has a JavaMail implementation. After downloading and unwilling the pop31_1_1.zip file, add POP3.jar to your ClassPath. This is followed by the installation of JavaBeans Activation Framework. All versions of the JavaMail API require JavaBeans Activation Framework to support input and corresponding processing of any data block. There is not much function, but you can find this basic MIME support in many browsers and email tools. After downloading the frame, unpack the JAF1_0_1.zip file and add the activation.jar file to the ClassPath. For JavaMail 1.2 users, you should now add mail.jar and activation.jar files to classpath. For JavaMail 1.1.3 users, now you should have added mail.jar, pop3.jar, and activation.jar files to classpath. If you don't plan to use POP3, you don't have to add POP3.jar to ClassPath. If you don't want to change the ClassPath environment variable, copy the JAR file to the lib / EXT directory in the Java Runtime Environment, JRE directory.

For example, the Default directory of the J2SE 1.3 release in the Windows platform C: /jdk1.3/jre/lib/ext. What are the core classes of the Java Mail API · Javax.mail.Session: Session class define a basic mail session (SESSION), which is the highest level of the Java Mail API. All other classes are effective via this session. The session object obtains information with java.util.properties objects, such as mail servers, usernames, passwords, and other information shared throughout the application. · Javax.mail.MAESSAGE: Once you get the session object, you can continue to create the message you want to send. This is done by the Message class. Because Message is an abstract class, you must use a subclass, in most cases, Javax.mail.Internet.mimeMeMessage. MimeMessage is an email message that can understand the MIME type and head, just as defined in different RFCs. Although the non-ASCII characters in some headers are also coded, the Message header can only be limited to a US-ASCII character. · Javax.mail.address: Once you have created session and message, you can use Address to determine the letters address with address after filling the content. Like Message, Address is also an abstract class. You are using the Javax.mail.Internet.InternetAddress class. · Javax.mail. AUTHENTICATOR: Like the Java.Net class, JavaMail API can also use Authenticator to access protected resources through the username and password. For JavaMail APIs, these resources are email servers. JavaMail Authenticator is in a javax.mail package, and it is different from the class authenticator in Java.net. Both do not share the same authenticator because JavaMail API is used for Java 1.1, which does not have a Java.net category. To use Authenticator, create a subclass of an abstract class and return to the PasswordAuthentication instance from the getPasswordAuthentication () method. Once you have finished, you must register an Authenticator to Session. Then, when you need to authenticate, you will notify Authenticator. You can pop up the window, or you can read the user name and password from the configuration file (although not encrypted is unsafe), return them to the call as the PasswordAuthentication object. · Javax.mail.Transport: The last part of the message is used to use the Transport class. This type of protocol specified language sends a message (usually SMTP). It is an abstract class, and its work is similar to the session. Only call the static send () method, you can use the default version of the class: Transport.send (Message); or readers can also get a specific instance from the session for your own protocol (if not If you need to pass it), send a message, then close the connection. · Javax.mail.Store: Store class implements read, write, monitor, lookup, etc. on a particular email protocol. You can access the Javax.mail.Folder class through the Javax.mail.Store class.

· Javax.mail.Folder: Folder class is used to hierarchical messages and provide the ability to access Email according to Javax.mail.Message format. How to send Email using JSP? Below we pass a simple example, how the email in JSP is sent. This example consists of two files. One is an HTML file to establish a form of mail information (including sender, recipient, theme, etc.) and send the form content to the JSP file; the other is the JSP page, responsible for the sending of the message. HTML file

from:
Subject:

Message: