JavaMail API to iMail -- java.net.SocketException: Permission denied: connect
Add -Djava.net.preferIPv4Stack=true
to the VM options. Another way to confirm if it is the same issue, in Netbeans, right click on the project > properties > Libraries and choose a JDK 6 Java Platform (install if you do not have it). Clean, build then try again. This will eliminate this issue as the problem
Credit https://stackoverflow.com/a/7478027/643500
JavaMail SocketException: Permission denied: connect
Possibly the property needs to be set when the JVM starts? Try running with "java -Djava.net.preferIPv4Stack=true -jar ...."
Possibly you have some anti-virus or firewall that preventing "java" from connecting, but allowing "telnet" to connect? Try turning off any anti-virus or firewall temporarily to test.
Javamail Permission denied: Connect after build
How are you running your program?
If you run it with "java -jar myprog.jar", use "java -Djava.net.preferIPv4Stack=tru -jar myprog.jar".
If you run it by double clicking the jar file or something like that, you might need to set the property in your code, by adding System.setProperty("java.net.preferIPv4Stack", "true");
JavaMail connection problems
java.net.SocketException: Permission denied: connect
This means you connected to the server and port and the server actively denied your connection.
If you try and telnet
to this server and port you might get a more descriptive message, either way, that port isn't going to work.
Most likely that port 25
is blocked as a security measure, this is pretty standard settings for most companies.
Since you are using Outlook can't find the port in the settings, I am assuming you are connecting to an Exchange server, which might not even have SMTP
enabled at all if your entire company is a Microsoft Outlook shop.
You will need to contact your system admin team to find out what port and protocol you should actually be using.
I get java.net.SocketException: Permission denied: connect when sending an email in Jenkins
Arguments after the -jar
argument will be passed to the application, not the java vm. So try moving -Djava.net.preferIPv4Stack=true
before the -jar
argument.
Azure - permission denied when trying to connect to external MySQL database
I tired to reproduce your issue but failed.
Here , I tried to create a java spring-boot
project to test connection with Azure MySQL Database
.
Snippet of my code:
private static String hostName = "<your host name>";
private static String dbName = "sys";
private static String user = "<user name>";
private static String password = "password";
private static String portNumber = "3306";
@RequestMapping("/hello")
public String index() throws SQLException {
Connection conn = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
String url = "jdbc:mysql://"+hostName+":"+portNumber+"/"+dbName+"?verifyServerCertificate=true&useSSL=true&requireSSL=false&serverTimezone=UTC";
conn = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
System.out.println("error!!!!");
System.out.println(e.getMessage());
e.printStackTrace();
return e.getMessage();
}
return conn.getCatalog();
}
My web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\demo-0.0.1-SNAPSHOT.jar"">
</httpPlatform>
</system.webServer>
</configuration>
You could check points as below if you can not connect to your database:
1.Don't miss set SSL parameters.
2.Please set white IP address
of your azure web app.
3.Don't miss -Djava.net.preferIPv4Stack=true
setting in your web.config
.
You could find more details from this thread: JavaMail API to iMail -- java.net.SocketException: Permission denied: connect
Hope it helps you.
Related Topics
How to Convert List to JSON in Java
Why Does This Generic Code Compile in Java 8
Using Jaxb to Cross Reference Xmlids from Two Xml Files
In Which Case Do You Use the JPA @Jointable Annotation
Java 8 Lambdas Group List into Map
Loading Raw 64-Byte Long Ecdsa Public Key in Java
How to Open a Windows Named Pipe from Java
Reserved Words as Names or Identifiers
How Often Should Connection, Statement and Resultset Be Closed in Jdbc
Java, Shifting Elements in an Array
How to Get the Session Object If I Have the Entity-Manager
Java.Util.Concurrentmodificationexception Not Thrown When Expected
How to Read Xml Response from a Url in Java
How to Get All Table Names from a Database
Simpledateformat Parse(String Str) Doesn't Throw an Exception When Str = 2011/12/12Aaaaaaaaa