Reputation: 690
I'm trying to run a jar file which sends a mail, using this command:
java -jar sendmail.jar
When I run the code from NetBeans everything works fine, but when I export to a jar file and run the jar file I get the following error:
Error Sending mailjavax.mail.MessagingException: Could not connect to SMTP host:
smtp.<xxx>.com, port: 25;
nested exception is:
java.net.SocketException: Permission denied: connect
After I got the error I executed the code from NetBeans, and the mail was sent. Thus I don't have any issue with SMTP or connection.
I think that the jar file cannot locate the mail.jar. Please advise.
Upvotes: 0
Views: 508
Reputation: 116
Be sure to put your mail.jar file into lib folder and also ensure that your lib folder and sendmail.jar files are present in same directory.
Upvotes: 0
Reputation: 2311
Does your machine by any chance use ipv6? if it does, you can try to start your jar with the -Djava.net.preferIPV4Stack=true
argument.
Upvotes: 1
Reputation: 717
Be sure that the mail.jar is probably imported under the libs and your not just referenced it.
Upvotes: 0