Installing JavaMail using Eclipse JavaSE 1.6
Would someone please be able to explain开发者_如何学C to me how to properly install JavaMail and have it to execute in Eclipse please.
I have been trying for the past few hours and I am completely lost as to why this is.
This is from trying to execute their demo projects msgsend.java and msgshow.java.
I either find an error message stating invalid protocol or could not connecto to SMTP host: localhost, port 25;
What I suggest.
- Open Eclipse
- Create a new Java project
- Create a new Java class which contains a main method (entry point)
- Create a folder "libs" inside which you put your JavaMail jar library and other external dependencies
- Right-click (from within eclipse) on the added JavaMail jar file and choose Build path and add to build path.
- Now you project should be ok in terms of dependencies and you can start coding your test logic within your main method or other classes you create
- Once coded, Run your project, by right-clicking on the class which represents your app's entry point and select Run and run as Java application
(That's all I can provide given the details in your question ;) )
If you're running the examples and it's using "localhost:25" as the server, you'll need to have an SMTP server running on the same machine.
If you don't have a local SMTP server, then try replacing "localhost" with the SMTP server hostname that your ISP provides you.
If you are getting an exception being thrown which is stating that it could not correct to an SMTP host (it may be helpful if you posted the exact error) that means that Javamail is correctly installed in your classpath but that it could not find the given SMTP host.
Keep in mind that by merely dropping Javamail into Eclipse will not automatically result in an SMTP server running on localhost (aka your own machine).
So, either set up an SMTP server on your machine or just use your ISP's server for test purposes.
I would suggest the later, but if you are interested in the former, you may want to check out: http://www.ericdaugherty.com/java/mailserver/
It includes an Eclipse plugin.
精彩评论