当我尝试从 Outlook Web 访问发送邮件时,出现连接重置异常

问题描述 投票:0回答:1

我已阅读有关此主题的多个博客,但无法调试该错误。 我正在尝试从我的公司 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("[email protected]"));
                message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("[email protected]"));
                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 jakarta-mail
1个回答
0
投票

异常意味着套接字被意外关闭。请参阅此 导致我的 java.net.SocketException 的原因:连接重置?

© www.soinside.com 2019 - 2024. All rights reserved.