Javamail FAQs: installation and configuration

Source: Internet
Author: User
Tags imap

Q. How can I install javamail API implementation?
A: Decompress the distribution ZIP file and edit the classpath environment variable to include the mail. jar file, which is included in javamail API distribution. You also need the implementation of the JavaBeans activation framework (see below. See readme files (in delivery) for other details and examples.
Q. Does javamail include all necessary email servers?
A: No. The javamail API package does not include any email server. To use the javamail API package, you will need to access the IMAP or POP3 mail server (for reading emails) and/or SMTP Mail Server (for sending emails ). These email servers are generally provided by Internet service providers or are part of the organizational network infrastructure. If you do not need to access such an email server, please read it down.
Q. Where can I obtain the necessary email server?
A: Sun Java System Messaging Server can be used on Solaris and Windows platforms. The IMAP server of the University of Washington supports multiple platforms (such as UNIX and 32-bit windows ). You can obtain the source code from the address ftp://ftp.cac.washington.edu/imap/imap.tar.z. Many other vendors provide mail servers that support Internet standards. You can obtain more information from IMAP connection and Internet Mail consortium.
Q. What host name, user name, or password should I use?
A: We do not provide an email server for you to use. You must use your own email server or an Internet service provider or an email server provided by your company. The network administrator may give you some necessary information to configure javamail to work with the mail server.
Q. How can I configure javamail to work through the proxy server?
A: Most proxy servers only Support HTTP. Javamail does not use HTTP to read or send emails. One of the main reasons for using the proxy server is to allow HTTP requests in the enterprise network to pass through the Enterprise Firewall. Firewalls usually block most Internet access requests, but allow requests from proxy servers to pass. In addition, the mail server in the enterprise network performs similar functions for mail, receives messages through SMTP, forwards them to the final destination on the Internet, and receives incoming messages, then they are sent to the appropriate internal email server.
If your proxy server supports socks V4 or V5 protocol (http://www.socks.nec.com/aboutsocks.html, rfc1928) and allows anonymous connections, you can tell the Java runtime to directly connect all TCP sockets to the SOCKS Server. See http://java.sun.com/j2se/1.4/docs/guide/net/properties.html to obtain the latest socksproxyhost and socksproxyport attributes. These are system-level attributes, not javamail session attributes. When calling applications, they can be set from the command line, for example, Java-dsocksproxyhost = myproxy .... This tool can be used to indicate SMTP, IMAP, and POP3 communication from javamail to the socks proxy server. Note that setting these properties will tell all TCP sockets to connect to the socks proxy, which may have a negative impact on other aspects of the application.
If there is no such SOCKS Server, if you want to use javamail to directly access the mail server outside the firewall, You need to configure a firewall to allow this access. A simple HTTP Proxy web server is sufficient.
Q. How do I set classpath in Windows NT?
A: For more information, see here.
Q. When trying to run a program in Linux, I got a very strange error message and the program failed. Where is the error?
A: Generally, the error message looks like the following:
Exception in thread "Main"
Java. Lang. verifyerror :( class: COM/Sun/mail/POP3/pop3store,
Method: Finalize signature :() V)
Illegal use of nonvirtual function call
The problem is that on Linux, The unzip command is a version with a bug. When javamail is decompressed to download the package, the unzip command destroys the mail. jar file. Obtain the unzip command of the latest version or decompress the downloaded package using the JDK jar command.
Q. How can I use javamail in an application running under securitymanager? What permissions must I grant to the application and javamail?
A: In JDK 1.2 (or later) with securitymanager, when javamail is used, javamail may fail to read the configuration file in the mail. jar file. When you read the configuration file from the activation. jar file, the same issue may occur with the JavaBeans activation framework. These default configuration files are stored as resource files and stored in the META-INF directory of the JAR file.
There are many Debugging techniques that can be used to determine whether this is a problem. Setting the "mail. debug" attribute of the session to true (or calling session. setdebug (true) will cause javamail to print debugging messages when trying to load various configuration files. Messages such as "Debug: Can't load default providers file" (Debug: cannot load default provider files) indicate that this problem may exist. Similarly, set the system attribute "javax. activation. debug "is" true "(for example, by using" Java-djavax. activation. DEBUG = true... "to run the program), it will cause JAF to print the debugging message when trying to load each resource file. Finally, by setting the system attribute "Java. security. debug "is" Access: failure "(for example, by using" Java-djava. security. DEBUG = Access: failure... JDK can generate useful debugging output.
In addition to the necessary permissions to read the configuration file, the application (and javamail) also requires certain permissions to connect to the mail server it uses. If the application uses the system property to configure javamail (for example, as many javamail demos do, it passes. getproperties () returns the properties object to the session constructor). It also requires certain permissions to use the system properties object. In addition, the application can use its own properties object and be sure to set "mail. from "attribute or" mail. user "and" mail. host "attribute (see internetaddress. getlocaladdress () method ).
In JDK 1.2 securitymanager, to enable the application to use javamail, the application, javamail, and JAF require certain permissions, for example, the following permissions (you must replace the Host Name and path name with appropriate values). Add these permissions to the security policy file used by the application.
Grant {
// Following Two permissions allow
// Access to default config files
Permission java. Io. filepermission
"/Path/to/mail. Jar", "read ";
Permission java. Io. filepermission
"/Path/to/activation. Jar", "read ";
// Following to use SMTP
Permission java.net. socketpermission
"Smtphost: 25", "Connect, resolve ";
// Following to use IMAP
Permission java.net. socketpermission
"Imaphost: 143", "Connect, resolve ";
// Following to use POP3
Permission java.net. socketpermission
"Pop3host: 110", "Connect, resolve ";
// Following needed if system. getproperties () is used
Permission java. util. propertypermission
"*", "Read, write ";
};
  
Q. How can I configure the Web server to run the javamail demo Servlet?
A: The following web server instructions can be obtained from:
Tomcat
Apache with jserv
IPlanet Web Server
Java Web Server
Q. When javamail is used in servlet, no javamail class is found. I have added mail. jar to the classpath of the server?
A: When classpath is changed, it is usually necessary to completely restart the web server.
Q. My servlet can find the javamail class, but javamail complained that it could not find the service provider or address type "rfc822" for "SMTP" or "IMAP ".
A: Generally, this is because javamail cannot access the configuration file in mail. jar, which may be caused by security permissions. Refer to this entry for more details. Make sure that you have not extracted the mail. Jar content. In the classpath of the server, include the mail. jar file that has not been changed.
Q. Where can I find JWS. jar? I have installed Java Web Server 2.0 and tried to run javamailservlet. The readme file instructs me to add JWS. jar to classpath.
A: JWS. jar is no longer released together with Java Web Server (in earlier versions, they are released together). Therefore, you do not need to add it to classpath. Add mail. jar and activation. jar to classpath, and restart Java Web server.

Recommended for beginners a programming technology learning site, 96 stack Software Programming Network, http://www.96dz.com, which has c ++ video tutorial, C # video tutorial, Java video tutorial download, c \ c ++, Java, and C #. net and other programming technology abstracts, including the current mainstream Linux programming and web programming learning materials video tutorial download.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.