Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.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
运行java SendMail时的HTTP状态404_Java_Eclipse_Tomcat - Fatal编程技术网

运行java SendMail时的HTTP状态404

运行java SendMail时的HTTP状态404,java,eclipse,tomcat,Java,Eclipse,Tomcat,我得到以下错误: address bar: http://localhost:8080/EmailNew/WEB-INF/classes/SendMail.java HTTP Status 404 - type Status report message description The requested resource is not available. Apache Tomcat/8.0.28 从EclipseEE和Tomcat8运行下面的代码 import java.io.Unsu

我得到以下错误:

address bar: http://localhost:8080/EmailNew/WEB-INF/classes/SendMail.java

HTTP Status 404 -
type Status report
message
description The requested resource is not available.

Apache Tomcat/8.0.28
从EclipseEE和Tomcat8运行下面的代码

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;





public class SendMail {

    public static void main(String[] args) {
        Properties props = new Properties();

    /*  props.setProperty("mail.host", "smtp.gmail.com");
        props.setProperty("mail.smtp.port", "587");
        props.setProperty("mail.smtp.auth", "true");
    */
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "587");
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "587");




        Authenticator auth = new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("abcxyz@gmail.com","xdkasaspajokzfcr");
            }
        };

        Session session = Session.getDefaultInstance(props, auth);

        Message msg = new MimeMessage(session);

        try {
            msg.setSubject("Email Test");
            msg.setText("We made it!!");
            msg.setFrom(new InternetAddress("abcxyz@gmail.com","Bob"));
            msg.setRecipient(Message.RecipientType.TO, new InternetAddress("abcxyz@gmail.com"));

            Transport.send(msg);
        } catch (MessagingException | UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        System.out.println("Finished.");
    }

}

请不要在公共论坛上发布您的电子邮件/密码。也请在帖子中包含异常stacktrace。我没有收到stacktrace。我不认为代码是可执行的。你在哪里得到“HTTP状态404”?我的crome浏览器打开,我收到消息请不要在公共论坛上发布你的电子邮件/密码。在帖子中还包括异常stacktrace。我没有得到stacktrace。我认为代码没有被执行。你在哪里得到“HTTP状态404”?我的crome浏览器打开,我得到消息