2014-07-09 71 views
0

大家好我想發送電子郵件使用網絡邏輯服務器..我可以很容易地發送電子郵件通過運行單個文件是java主,但無法使用網絡邏輯發送它。我我得到以下例外...(發送郵件從weblogic 10.3

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 

這裏是我的代碼:

Properties props = System.getProperties();  
props.put("mail.smtp.user", SMTP_AUTH_USER); 
props.put("mail.smtp.password", SMTP_AUTH_PWD); 
props.setProperty("mail.transport.protocol", "smtp"); 
props.put("mail.smtp.starttls.enable", "true"); 
props.put("mail.imaps.ssl.trust", "*"); 
props.put("mail.smtp.ssl.trust", "smtp.gmail.com"); 
props.put("mail.smtp.host", SMTP_HOST_NAME); 
props.put("mail.smtp.auth", "true"); 
props.put("mail.smtp.port", "587"); 
Session session = Session.getInstance(props, 
new javax.mail.Authenticator() { 
protected PasswordAuthentication getPasswordAuthentication() { 
     return new PasswordAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD); 
    } 
}); 


System.out.println("Created session"); 
session.setDebug(true); 

    Transport transport = session.getTransport("smtp"); 
    System.out.println("Got Transport from session"); 


    MimeMessage message = new MimeMessage(session); 
    message.setSubject("Movies Store Ticket Confirmation"); 
    message.setContent(" Dear Farish,\n \n Your Ticket Booking is Confirmed. Thank you for booking the ticket.\n \n " + 
     "Movie name : EndGame \n " + 
     "Theater Name : Mstore \n " + 
     "Screen  : Screen A \n " + 
     "Selected Seat: B04 B05 \n " + 
     "Amount  : 160 \n " + 
     "Show Date : 05/07/2014 \n " + 
     "Show Time : 10:00 AM ", "text/plain"); 
    message.setFrom(new InternetAddress("******@gmail.com")); 
    message.addRecipient(Message.RecipientType.TO, 
     new InternetAddress("********@gmail.com")); 
    System.out.println("Before Connecting"); 
    transport.connect(SMTP_HOST_NAME,SMTP_AUTH_USER,SMTP_AUTH_PWD); 
    System.out.println("After Connecting"); 
    transport.sendMessage(message, 
     message.getRecipients(Message.RecipientType.TO)); 
    System.out.println("After Sensing"); 
    transport.close(); 

} 

有人請幫我在這... 在此先感謝...

回答

0

看着你除您正試圖使用​​需要安全證書的安全服務器發送電子郵件。檢查電子郵件服務器文檔以瞭解如何在您的程序中啓用安全性問題。

0

在下面的transport.connect語句中給出端口no。 transport.connect(SMTP_HOST_NAME,SMTP_PORT,SMTP_AUTH_USER,SMTP_AUTH_PWD);

+0

感謝您的回覆..我會盡力.. – FarishMohammed

+0

我試過了......它不工作......給我同樣的例外.. – FarishMohammed