Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法将会话解析为通过jsp发送邮件的类型 我想从我的jsp页面发送电子邮件。我正在使用ApacheTomcat服务器并在本地主机上运行。我参考了这个链接来指导我。我还在JangoSMTP上创建了一个帐户,并在下面的代码中提供了用户名和密码。但是,我得到的错误是: 这是我的index.html:- 使用JSP发送电子邮件 使用JSP发送电子邮件 _Jsp_Email_Session_Tomcat_Smtp - Fatal编程技术网

无法将会话解析为通过jsp发送邮件的类型 我想从我的jsp页面发送电子邮件。我正在使用ApacheTomcat服务器并在本地主机上运行。我参考了这个链接来指导我。我还在JangoSMTP上创建了一个帐户,并在下面的代码中提供了用户名和密码。但是,我得到的错误是: 这是我的index.html:- 使用JSP发送电子邮件 使用JSP发送电子邮件

无法将会话解析为通过jsp发送邮件的类型 我想从我的jsp页面发送电子邮件。我正在使用ApacheTomcat服务器并在本地主机上运行。我参考了这个链接来指导我。我还在JangoSMTP上创建了一个帐户,并在下面的代码中提供了用户名和密码。但是,我得到的错误是: 这是我的index.html:- 使用JSP发送电子邮件 使用JSP发送电子邮件 ,jsp,email,session,tomcat,smtp,Jsp,Email,Session,Tomcat,Smtp,请告诉我错误在哪里!我在谷歌上搜索了很多,但找不到答案。提前谢谢 包括.jar文件 $TOMCAT_HOME 箱子 形态 解放党 ... 网络应用 test.jsp(可以位于除WEB-INF之外的任何目录下) WEB-INF 解放党 mail.jar activation.jar您在CLASSPATH还是lib文件夹中有mail.jar?@Rembo:在CLASSPATH中。这会有区别吗?好的……我想那是个错误。但现在我得到了错误:结果:错误:无法发送消息。。。。那么,我应该如何解决它呢?我在控

请告诉我错误在哪里!我在谷歌上搜索了很多,但找不到答案。提前谢谢

包括.jar文件

$TOMCAT_HOME 箱子 形态 解放党 ... 网络应用 test.jsp(可以位于除WEB-INF之外的任何目录下) WEB-INF 解放党 mail.jar
activation.jar

您在CLASSPATH还是lib文件夹中有
mail.jar
?@Rembo:在CLASSPATH中。这会有区别吗?好的……我想那是个错误。但现在我得到了错误:结果:错误:无法发送消息。。。。那么,我应该如何解决它呢?我在控制台中得到错误消息:javax.mail.SendFailedException:Sending failed;嵌套异常为:类javax.mail.MessaginException:未知SMTP主机:relay.jangosmtp.net;用您当前的问题详细信息更新您的问题,并完成stacktrace。请您详细说明您的答案,再添加一点关于您提供的解决方案的说明,好吗?
An error occurred at line: 24 in the jsp file: /index2.jsp
Session cannot be resolved to a type
21:         props.put("mail.smtp.port", "25");
22:      
23:         //Get the Session object.
24:         Session mailSession = Session.getInstance(props,
25:                 new javax.mail.Authenticator() {
26:                     protected PasswordAuthentication getPasswordAuthentication() {
27:                         return new PasswordAuthentication(username,
<%@ page import="java.io.*,java.util.*,javax.mail.*"%>
        <%@ page import="javax.mail.internet.*,javax.activation.*"%>
        <%@ page import="javax.servlet.http.*,javax.servlet.*"%>
        <%
            String result;
            //Recipient's email ID needs to be mentioned.
            String to = "xyz@gmail.com";

            // Sender's email ID needs to be mentioned
            String from = "abc@gmail.com";
            final String username = "username";
            final String password = "password";

            // Assuming you are sending email through relay.jangosmtp.net
            String host = "relay.jangosmtp.net";

            Properties props = new Properties();
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.host", host);
            props.put("mail.smtp.port", "25");

            //Get the Session object.
            Session mailSession = Session.getInstance(props,
                    new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(username,
                                    password);
                        }
                    });

            try {
                // Create a default MimeMessage object.
                Message message = new MimeMessage(mailSession);

                // Set From: header field of the header.
                message.setFrom(new InternetAddress(from));

                // Set To: header field of the header.
                message.setRecipients(Message.RecipientType.TO,
                        InternetAddress.parse(to));

                // Set Subject: header field
                message.setSubject("Testing Subject");

                // Now set the actual message
                message.setText("Hello, this is sample for to check send "
                        + "email using JavaMailAPI in JSP ");

                // Send message
                Transport.send(message);

                System.out.println("Sent message successfully....");
                result = "Sent message successfully....";

            } catch (MessagingException e) {
                e.printStackTrace();
                result = "Error: unable to send message....";

            }
        %>
        <html>
        <head>
        <title>Send Email using JSP</title>
        </head>
        <body>
            <center>
                <h1>Send Email using JSP</h1>
            </center>
            <p align="center">
                <%
                    out.println("Result: " + result + "\n");
                %>
            </p>
        </body>
        </html>