javax.mail.MessagingException: 501 5.0.0 Invalid domain name

Hallo,

I want to send mails via sendmail.

but I get this error if I try to send.

The reason can be following :

in this company there are 2 mail servers mailext and mailint

our smtp server ist mailext but this use the mailint's certificate. (also the name is false) can this be a reason? how can I set up that java accepts the certs with mailint too ?

these are the settings

String host="mailext.server";

String username = "username@server";

String password = "password";

String sender ="username@server";

String port = "25";

Properties props = new Properties();

props.put("mail.smtp.user", username);

props.put("mail.smtp.host", host);

props.put("mail.smtp.port", port);

props.put("mail.smtp.starttls.enable","true");

props.put("mail.smtp.auth", "true");

props.put("mail.smtp.debug", "true");

props.put("mail.smtp.socketFactory.port", port);

I have tried this code with googlemails setting and it functions.

[1049 byte] By [Kezmana] at [2007-11-27 7:58:58]
# 1

I don't think it's a cert problem. I think your client isn't setting a valid

domain name when connecting to your server. Look at the entire

protocol trace to find out.

You might need to set the mail.smtp.localhost property if your name

service doesn't provide a valid name for your client machine. See

the com.sun.mail.smtp package javadocs.

bshannona at 2007-7-12 19:40:56 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hallo Bshannon,

thanks for your Antwort.

I have tried it now witk localhost setting and get this error

javax.mail.MessagingException: Can't send command to SMTP host;

nested exception is:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1420)

at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1408)

at com.sun.mail.smtp.SMTPTransport.ehlo(SMTPTransport.java:847)

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

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

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

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

at javax.mail.Transport.send0(Transport.java:168)

at javax.mail.Transport.send(Transport.java:98)

at manager.CertificateManager.sendMail(CertificateManager.java:524)

at manager.CertificateManager.run(CertificateManager.java:190)

at java.lang.Thread.run(Thread.java:595)

Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1518)

at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)

at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:848)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)

at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)

at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:818)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1030)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:622)

at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)

at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:101)

at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)

at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)

at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1418)

... 11 more

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:

unable to find valid certification path to requested target

at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:221)

at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:145)

at sun.security.validator.Validator.validate(Validator.java:203)

at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:172)

at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:841)

... 22 more

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:236)

at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:194)

at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:216)

... 27 more

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1518)

at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)

at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:848)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)

at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)

at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:818)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1030)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:622)

at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)

at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:101)

at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)

at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)

at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1418)

at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1408)

at com.sun.mail.smtp.SMTPTransport.ehlo(SMTPTransport.java:847)

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

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

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

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

at javax.mail.Transport.send0(Transport.java:168)

at javax.mail.Transport.send(Transport.java:98)

at manager.CertificateManager.sendMail(CertificateManager.java:524)

at manager.CertificateManager.run(CertificateManager.java:190)

at java.lang.Thread.run(Thread.java:595)

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:

unable to find valid certification path to requested target

at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:221)

at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:145)

at sun.security.validator.Validator.validate(Validator.java:203)

at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:172)

at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)

at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:841)

... 22 more

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:236)

at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:194)

at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:216)

... 27 more

now it seems to be a certificate problem :) the reason can be the difference that I have written in my first post.

How can I overcome this?

many thanks

Kezmana at 2007-7-12 19:40:56 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
PROBLEM SOLVEDhallo,I have found out that the sendmail on our server doesn't support the SSL the 2. error was because of this.and the first error is like bshonnen said, because of localhost definition.Many Thanks
Kezmana at 2007-7-12 19:40:56 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...