Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

windows 7 - I get java.net.SocketException: Permission denied: connect when sending an email in Jenkins

My Configuration:

  • Windows 7 machine
  • Java 7
  • Jenkins 1.511 running as Service on Local Account

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>

My hudson.tasks.Mailer.xml file

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

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

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)

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.

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.

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.

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.

My questions

  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.

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

Some Notes:

  • I cannot uninstall Java 7 due to lame corporate issues.
  • I cannot install Java 6 due to the same issues.
  • I am allowed to install the IBM JDK/JRE.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...