Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » javamail access restriction error
javamail access restriction error [message #496072] Sat, 07 November 2009 19:14 Go to next message
Eclipse UserFriend
Hi,

I'm already programming for a year now in Eclipse. Today I started on a new project, this time one for myself. In the past I always could find the answers on one of the forums I check out.

I'm trying to initiate and build my own mailing program in JAVA. After looking around I found the package `javamail` from the SUN site. I also implemented the activation package, as required.

After downloading I placed them in JRE/lib folder, and added both to my project.

files:
- javamail 1.4.2.jar
- activation 1.1.1.jar

I found some code on the internet on how to send e-mail through JAVA.

import javax.mail.Session;
import javax.mail.Message;
import javax.mail.Transport;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.InternetAddress;
import java.util.Properties;

public class mail {
    public static void main(String[] args) {
        String from = "user@some-domain.com";
        String to = "user@some-domain.com";
        String subject = "Hi There...";
        String text = "How are you?";

        Properties properties = new Properties();
        properties.put("mail.smtp.host", "smtp.some-domain.com");
        properties.put("mail.smtp.port", "25");
        Session session = Session.getDefaultInstance(properties, null);

        try {
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setSubject(subject);
            message.setText(text);

            Transport.send(message);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }


The functionality of this I do understand completely, only there is a problem. This code gives a error, a Access Restriction error:

Access restriction: The method is not accessible due to restriction on required library D:\ ... \jre6\lib\javamail-1.4.2\mail.jar


Does someone know how I can solve this problem?

With regards,

farmer-duck
Re: javamail access restriction error [message #503071 is a reply to message #496072] Thu, 10 December 2009 13:43 Go to previous messageGo to next message
Eclipse UserFriend
Eclipse is searching JRE JARs before the javamail.jar that you supplied. On the project's context menu, select Build Path | Configure Build Path and make certain that your supplied JAR is above JRE System Library. You may have similar problems with activation.jar -- I do. I'd just make certain that the JRE stays last on the library list.

I have no idea why Eclipse thinks this stuff should be restricted. Many have run into this or similar mystery restrictions.
Re: javamail access restriction error [message #503146 is a reply to message #496072] Fri, 11 December 2009 02:30 Go to previous message
Eclipse UserFriend
I found it. Thank you!

Indeed this shouldn't be that hard to implement.

Greeting,

Farmer-duck
Previous Topic:J2ME creating package
Next Topic:eclipse unit tests don't support 'assert'?
Goto Forum:
  


Current Time: Thu Mar 27 13:46:53 EDT 2025

Powered by FUDForum. Page generated in 0.04512 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top