我得到 java.net.SocketException: Permission denied: 在 Jenkins 中发送电子邮件时连接

I get java.net.SocketException: Permission denied: connect when sending an email in Jenkins(我得到 java.net.SocketException: Permission denied: 在 Jenkins 中发送电子邮件时连接)

本文介绍了我得到 java.net.SocketException: Permission denied: 在 Jenkins 中发送电子邮件时连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的配置:

  • Windows 7 机器
  • Java 7
  • Jenkins 1.511 在本地帐户上作为服务运行

我的 jenkins.xml 文件

My jenkins.xml file

<service>
  <id>jenkins</id>
  <name>Jenkins</name>
  <env name="JENKINS_HOME" value="%BASE%"/>
  <executable>C:Program FilesIBMSDP8.5jdkinjava.exe</executable>
  <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%jenkins.war" --httpPort=8080 -Djava.net.preferIPv4Stack=true</arguments>
</service>

我的 hudson.tasks.Mailer.xml 文件

My hudson.tasks.Mailer.xml file

<hudson.tasks.Mailer_-DescriptorImpl plugin="mailer@1.4">
  <defaultSuffix>@example.com</defaultSuffix>
  <hudsonUrl>http://localhost:8081/</hudsonUrl>
  <adminAddress>Jenkins Build Server &lt;do-not-reply@example.com&gt;</adminAddress>
  <smtpHost>smtp.example.com</smtpHost>
  <useSsl>false</useSsl>
  <charset>UTF-8</charset>
</hudson.tasks.Mailer_-DescriptorImpl>

注意:example.com"替换了我的真实域/电子邮件/smtp 服务器.

Note: "example.com" substituted for my real domain/email/smtp server.

当我指示 Jenkins 发送测试电子邮件时,我收到此错误:

When I instruct Jenkins to send a test email, I get this error:

Failed to send out e-mail

javax.mail.MessagingException: Could not connect to SMTP host: smtp.example.com, port: 25;
nested exception is:
java.net.SocketException: Permission denied: connect

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)

at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)

at javax.mail.Service.connect(Service.java:295)

我对这个错误的理解是,Java 7 暴露了 Windows 中的一个错误,涉及防火墙以及 Java 7 如何使用 ipv4 映射的 ipv6 地址.

My understanding with this error, is that there is a bug in Windows which is exposed by Java 7 with regards to the Firewall and how Java 7 uses a ipv4 mapped ipv6 address.

据报道,这可以通过在 java 运行时添加 -Djava.net.preferIPv4Stack=true 来解决.我已经成功地使用 ANT 电子邮件任务在这台机器上添加了 -Djava.net.preferIPv4Stack=true.但是,在詹金斯,我没有任何运气.

This is reported to be solved by adding -Djava.net.preferIPv4Stack=true to the java run time. I have had success with adding -Djava.net.preferIPv4Stack=true on this machine using the ANT email task. However, in Jenkins, I have not had any luck.

请注意,jenkins.xml 文件似乎被完全忽略了.-Djava.net.preferIPv4Stack=true 参数未设置.PATH 和 JAVA_HOME 都指向 IBM 运行时,但 Jenkins 仍然从 Oracle v7 运行时开始.Jenkins 必须生成一个新进程来启动和启动系统 java 7.

Note that it appears the jenkins.xml file is completely ignored. The -Djava.net.preferIPv4Stack=true parameter is not set. The PATH and JAVA_HOME both point to the IBM run time, but Jenkins still starts with the Oracle v7 run time. Jenkins must be spawning off a new process to start and picking up the system java 7.

使用上述配置,如果我转到 Jenkins 脚本控制台并使用System.getProperty("java.net.preferIPv4Stack") 询问它,我什么也得不到(未设置).如果我设置了该参数,我仍然会得到错误.如果我将 -Djava.net.preferIPv4Stack=true 添加到命令行(不使用服务),通过脚本控制台询问时仍然没有设置.

Using the above configuration, if I go to Jenkins scripting console and interrogate it using "System.getProperty("java.net.preferIPv4Stack"), I get nothing (not set). If I set that parameter, I still get the error. If I add -Djava.net.preferIPv4Stack=true to the command line (not using the service), it is still not set when interrogated through the scripting console.

我的问题

  1. 为什么会出现此错误以及如何解决?请记住,我可以编写一个使用相同的 smtp 服务器和 java 运行时间成功发送电子邮件的 ANT 脚本.

  1. Why am I getting this error and how to I resolve it? Remember that I can write an ANT script that successfully sends email using the same smtp server and java run times.

如何让 Jenkins 使用 -Djava.net.preferIPv4Stack=true 参数和指定的运行时间启动?

How do I get Jenkins to start up with the -Djava.net.preferIPv4Stack=true parameter and specified run time?

一些注意事项:

  • 由于蹩脚的公司问题,我无法卸载 Java 7.
  • 由于同样的问题,我无法安装 Java 6.
  • 我可以安装 IBM JDK/JRE.

推荐答案

-jar 参数后的参数将被传递给应用程序,而不是 java vm.因此,请尝试在 -jar 参数之前移动 -Djava.net.preferIPv4Stack=true.

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.

这篇关于我得到 java.net.SocketException: Permission denied: 在 Jenkins 中发送电子邮件时连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:我得到 java.net.SocketException: Permission denied: 在 Jenkins 中发送电子邮件时连接

基础教程推荐