Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
devaraj s
unable to send mail from liferay portlet
May 28, 2013 10:37 PM
Answer

devaraj s

Rank: Regular Member

Posts: 207

Join Date: May 21, 2012

Recent Posts

Hi , I have configured smtp in liferay control panel. I need to send a mail frm liferay portlet but I am facing exce[tion like unable to find valid certification path to requested target, Please can anyone let me know what is the issue.

here is my code,
 1public void sendMail( ActionRequest actionRequest, ActionResponse actionResponse)
 2            throws IOException, PortletException
 3            {
 4               
 5               MailMessage mailMessage = new MailMessage();
 6               mailMessage.setHTMLFormat(true);
 7               mailMessage.setBody("set body here");
 8               mailMessage.setFrom(new InternetAddress("xx@gmail.com","xx"));
 9               mailMessage.setSubject("set mail subject here");
10               try {
11                mailMessage.setTo(new InternetAddress("xyz@gmail.com"));
12            } catch (AddressException e) {
13                // TODO Auto-generated catch block
14                e.printStackTrace();
15            }
16               MailServiceUtil.sendEmail(mailMessage);
17               System.out.println("mail sent!");



Exception,
 1 ERROR [liferay/mail-1][MailEngine:567] Exception reading response
 205:30:40,694 ERROR [liferay/mail-1][MailEngine:154] sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
 3    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
 4    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
 5    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:289)
 6    at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:200)
 7    at sun.security.validator.Validator.validate(Validator.java:218)
 8    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
 9    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
10    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
11    at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1053)
12    at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:128)
13    at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:529)
14    at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:465)
15    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)
16    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1120)
17    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:744)
18    at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
19    at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
20    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
21    at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
22    at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)


Thanks in advance
Bart Simpson
RE: unable to send mail from liferay portlet
May 28, 2013 11:02 PM
Answer

Bart Simpson

Rank: Liferay Master

Posts: 524

Join Date: August 29, 2011

Recent Posts

Are you configuring the smtp server to be secured? Is it using SSL anywhere? That could be an issue.
devaraj s
RE: unable to send mail from liferay portlet
May 28, 2013 11:22 PM
Answer

devaraj s

Rank: Regular Member

Posts: 207

Join Date: May 21, 2012

Recent Posts

Bart Simpson:
Are you configuring the smtp server to be secured? Is it using SSL anywhere? That could be an issue.


Thanks for response Bart Simpson, As your suggestion I have unchecked use secure network connection in control panel. Now I am not getting the above exception. my code exicuting without exception.

But I am not able get a mail to as I have set in my code. Please can you have a look on my code, is because of unchecking secure network connection or code issue ,mail is not getting?
Manish Yadav
RE: unable to send mail from liferay portlet
May 28, 2013 11:48 PM
Answer

Manish Yadav

Rank: Expert

Posts: 385

Join Date: May 26, 2012

Recent Posts

It happens because of server has self signed certificate. To resolve issue you can add this certificate to the list of trusted certificates of your JVM. Check below URL for procedures to add certificates in JVM.
1
2http://stackoverflow.com/questions/6908948/java-sun-security-provider-certpath-suncertpathbuilderexception-unable-to-find
3http://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed.html
devaraj s
RE: unable to send mail from liferay portlet
May 29, 2013 1:05 AM
Answer

devaraj s

Rank: Regular Member

Posts: 207

Join Date: May 21, 2012

Recent Posts

I agree for your point manish, I was succeded to send create account notification to user by setting smtp server details in control panel before. For that I have not configured any ssl security that time.

My question here is , Is we need to compulsarly follow ssl security to send a mail from liferay custom portlet? Why not needed any ssl configuration to get mail for account created notification? what is the difference here.
devaraj s
RE: unable to send mail from liferay portlet
June 3, 2013 12:19 AM
Answer

devaraj s

Rank: Regular Member

Posts: 207

Join Date: May 21, 2012

Recent Posts

Its worked emoticon Thanks
sadhan paul
RE: unable to send mail from liferay portlet
December 6, 2013 1:55 AM
Answer

sadhan paul

Rank: New Member

Posts: 2

Join Date: October 23, 2013

Recent Posts

devaraj s:
Its worked emoticon Thanks

i am also facing same type of problem. can you tell the steps in details please...
Tibor Jándi
RE: unable to send mail from liferay portlet
March 3, 2015 2:09 AM
Answer

Tibor Jándi

LIFERAY STAFF

Rank: New Member

Posts: 2

Join Date: September 29, 2011

Recent Posts

Please double check if there is a firewall that blocks the smtp.
I use Avast that causes this issue.