2016-01-23 121 views
0

這是我在jsp中用於電子郵件驗證的代碼。我已經嘗試了一切,但沒有得到爲什麼這個問題仍然存在。 它給出了錯誤未知的主機smtp.gmail.com和..8更多。我也嘗試調試也。 請幫忙!JSP頁面無法解析地址'smtp.gmail.com'

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> 
<%@ page import= "javax.servlet.*" %> 
<%@ page import= "javax.servlet.http.*" %> 
<%@ page import= "java.io.*" %> 
<%@ page import= "java.sql.*"%> 
<%@ page import= "java.util.*"%> 
<%@ page import= "javax.mail.*"%> 
<%@ page import= "javax.mail.internet.*"%> 
<%@ page import= "javax.activation.*"%> 
<%String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
    <head> 
    <base href="<%=basePath%>"> 

    <title>sign up successful</title> 

    <meta http-equiv="pragma" content="no-cache"> 
    <meta http-equiv="cache-control" content="no-cache"> 
    <meta http-equiv="expires" content="0">  
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
    <meta http-equiv="description" content="This is my page"> 
    <!-- 
    <link rel="stylesheet" type="text/css" href="styles.css"> 
    --> 

    </head> 

    <body> 

    <%! 

    public static String from="***";// provide the sender's email address here 
    public static String password="****";// provide the sender's password here 

    %> 
    <% 

      String pass="1234"; 
      String msg="password="+pass; 
      String subject="successsss"; 
      //PrintWriter out=response.getWriter(); 
      String to[]=request.getParameterValues("to"); 
     // String msg=req.getParameter("pass"); 
     // String subject=req.getParameter("subject"); 
      System.out.println("to:->"+to); 
      int i = 0; 

      Properties properties = System.getProperties(); 
      properties.put("mail.smtp.starttls.enable", "true"); 
      properties.put("mail.smtp.host", "smtp.gmail.com"); 


      properties.put("mail.smtp.port", "587"); 
      properties.put("mail.smtp.auth", "true"); 



      Session a = Session.getInstance(properties, new javax.mail.Authenticator() 
      { 
      protected PasswordAuthentication getPasswordAuthentication() 
      { 
      return new PasswordAuthentication(from, password); 
      } 
      } 
      ); 


     try 
     { 
     final MimeMessage message = new MimeMessage(a); 
     message.setFrom(new InternetAddress(from)); 
     InternetAddress[] addressTo = new InternetAddress[to.length]; 
      for (int j = 0; j < to.length; j++) 
      { 
       addressTo[j] = new InternetAddress(to[j]); 
      } 
      message.setRecipients(Message.RecipientType.BCC, addressTo); 
      message.setSubject(subject); //set subject 


      message.setText(msg); //set message 


      new Thread(new Runnable() 
      { 
      public void run() 
      { 
       try 
       { 
        Transport.send(message); 
       } 
       catch (Exception e){e.printStackTrace();} 
      } 
      }).start(); 


      out.println(" message sent successfully ....will reach in 10 or 15 seconds"); 

      session = null; 
      i = 1; 
     } 
      catch (MessagingException mex) 
      { 
      mex.printStackTrace(); 
      // return i; 
      } 
      //return i; 



    %> 

    <b>You have registered successfully. A varification code has been sent to your mail. Please Activate your account and login.<br><br></b> 
    <jsp:include page="login2.jsp"></jsp:include> 
    </body> 
</html> 
+0

謝謝yole ..有什麼我可以自己做.. – jyoti

回答

0

這是一個DNS問題,而不是一個編碼問題。您的本地DNS無法解析該主機名。諮詢你的網絡管理員。