当我试图从OutlookWebAccess发送邮件时,出现java运行时异常
我已经阅读了多篇关于这个主题的博客,但无法调试错误。 我正在尝试从我的公司outlook web access发送邮件。代码如下:当我试图从OutlookWebAccess发送邮件时,出现java运行时异常,java,email,outlook,Java,Email,Outlook,我已经阅读了多篇关于这个主题的博客,但无法调试错误。 我正在尝试从我的公司outlook web access发送邮件。代码如下: package ReadOutlook; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session;
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
任何帮助都将不胜感激。异常意味着套接字意外关闭。请看此谢谢您的回复。我无法用你提到的那篇文章来解决这个问题。我所在的网络使用代理。这可能是这个错误的原因吗?如果是这样的话,我该怎么处理呢?我再次检查了。我正在尝试访问公司电子邮件,所以没有使用代理。你能提出一些建议吗?检查这个以便更好地理解检查这个