JSP页面无法解析地址' smtp.gmail.com'

时间:2016-01-23 19:20:59

标签: jsp

这是我在jsp中进行电子邮件验证的代码。我已经尝试了一切,但没有得到为什么这个问题仍然存在。 它给错误未知主机smtp.gmail.com 和..更多.i也试过调试。 请帮忙!

<%@ 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>

1 个答案:

答案 0 :(得分:0)

这是一个DNS问题,而不是编码问题。您的本地DNS无法解析该主机名。咨询您的网络管理员。