Results 1 to 1 of 1
- 02-06-2011, 11:45 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
error in sending mail on my web app
hello all
I use JavaMailAPI for sending mail on my web application and write a servlet and use this codes for sending mail on that sevlet
and the below method called from above codeJava Code:Properprops = new Properties(); props.setProperty("mail.transport.protocol", "smtp"); props.setProperty("mail.host", "smtp.salekanpublishing.ir"); props.setProperty("mail.mime.charset", "UTF-8"); props.setProperty("mail.smtp.auth", "true"); props.setProperty("mail.smtp.starttls.enable", "true"); SMTPAuthenticator auth = new SMTPAuthenticator(); mailSession=Session.getDefaultInstance(props, auth); message=new MimeMessage(mailSession); try { message.setFrom(new InternetAddress(USER)); Address addressTo[]=new Address[1]; for (int i = 0; i < addressTo.length; i++) { addressTo[i]=new InternetAddress("iman.esmaeili.14@gmail.com"); } message.setRecipients(Message.RecipientType.TO, addressTo); message.setSubject("test mail"); message.setContent("<table>" + "<tr><td>test mail</td></tr>"+ "<tr><td>this is a test mail</td></tr>" + "</table>", "text/html; charset=UTF-8"); Transport.send(message); out.print("email sent correctly"); } catch (AddressException ex) { out.print("the address is incorrect"); Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex); } catch (MessagingException ex) { out.print("sending email failed"); Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex); }
but when i call and execute this servlet the below exception thrownJava Code:private class SMTPAuthenticator extends javax.mail.Authenticator{ public PasswordAuthentication getPasswordAuthentication() { String username = "MyUsername"; String password = "MyPassword"; return new PasswordAuthentication(username, password); } }
Java Code:javax.mail.MessagingException: Could not convert socket to TLS; 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.startTLS(SMTPTransport.java:1652) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:534) at javax.mail.Service.connect(Service.java:313) at javax.mail.Service.connect(Service.java:172) at javax.mail.Service.connect(Service.java:121) at javax.mail.Transport.send0(Transport.java:190) at javax.mail.Transport.send(Transport.java:120)
Similar Threads
-
Error in sending mail using ssl server
By fierof2 in forum NetworkingReplies: 5Last Post: 01-27-2011, 05:43 AM -
problem with sending mail usin javaX.mail api
By sandeepsai39 in forum New To JavaReplies: 4Last Post: 11-25-2009, 05:37 AM -
Sending a Mail
By haiforhussain in forum Advanced JavaReplies: 7Last Post: 07-30-2008, 12:28 AM -
Sending a mail with the local mail program
By thedude in forum Advanced JavaReplies: 2Last Post: 07-23-2007, 12:19 PM -
Sending mail Using JAVAMAIL
By peiceonly in forum Advanced JavaReplies: 3Last Post: 07-19-2007, 02:11 PM


LinkBack URL
About LinkBacks

Bookmarks