我得到java.net.SocketException:权限被拒绝:在Jenkins中发送电子邮件时连接 [英] I get java.net.SocketException: Permission denied: connect when sending an email in Jenkins

查看:3163
本文介绍了我得到java.net.SocketException:权限被拒绝:在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 Files\IBM\SDP8.5\jdk\bin\java.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)

我对此错误的理解是,Windows 7中存在一个由Java 7公开的问题到防火墙以及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方面取得了成功。但是,在Jenkins,我没有运气。

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. 为什么我会收到此错误以及如何解决?请记住我可以编写一个ANT脚本,使用相同的smtp服务器和java运行时间成功发送电子邮件。

  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。 / li>
  • 我无法安装J. ava 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:权限被拒绝:在Jenkins中发送电子邮件时连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆