gpt4 book ai didi

java - 当我尝试从 Outlook Web 访问发送邮件时出现 java 运行时异常

转载 作者:太空宇宙 更新时间:2023-11-04 14:33:25 25 4
gpt4 key购买 nike

我已阅读有关此主题的多个博客,但无法调试该错误。我正在尝试从我的公司 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

如有任何帮助,我们将不胜感激。

最佳答案

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

关于java - 当我尝试从 Outlook Web 访问发送邮件时出现 java 运行时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25868300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com