【问题标题】:I get java runtime exception when I am trying to send mail from outlook web access当我尝试从 Outlook Web 访问发送邮件时出现 java 运行时异常
【发布时间】:2014-11-10 04:12:18
【问题描述】:

我已阅读有关此主题的多个博客,但无法调试错误。 我正在尝试从我的公司 Outlook Web 访问发送邮件。这是代码:

package ReadOutlook;

import java.util.Properties;
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 email_readClass {      
            public static void main(String[] args) {final String username = "user1";
            final String password = "pass1";
            Properties props = new Properties();
            props.put("mail.transport.protocol", "smtp");
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.host", "email.company.com");
            props.put("mail.smtp.port", "443");

            Session session = Session.getInstance(props,
              new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
              });

            try {

                Message message = new MimeMessage(session);
                message.setFrom(new InternetAddress("user1@company.com"));
                message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("user1@company.com"));
                message.setSubject("Test");
                message.setText("HI");

                Transport.send(message);

                System.out.println("Done");

            } catch (MessagingException e) {
                throw new RuntimeException(e);
            }
        }
        }

这是我看到的错误:

Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Exception         reading response;
  nested exception is:
java.net.SocketException: Connection reset
at ReadOutlook.email_readClass.main(email_readClass.java:45)
Caused by: javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:297)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at ReadOutlook.email_readClass.main(email_readClass.java:40)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
... 8 more

任何帮助将不胜感激。

【问题讨论】:

    标签: java email outlook


    【解决方案1】:

    异常意味着套接字被意外关闭。看到这个What's causing my java.net.SocketException: Connection reset?

    【讨论】:

    猜你喜欢
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 2012-09-05
    • 2016-02-01
    • 2018-06-24
    • 2021-02-15
    • 2012-07-12
    • 1970-01-01
    相关资源
    最近更新 更多