这个错误让我发疯。当我的应用程序抛出异常时,我正在尝试向自己发送电子邮件,但我刚刚开始收到此错误。我能够成功 ping 主机,并且在使用 nslookup 时可以获得本地 IP 地址。有任何想法吗?谢谢
try
{
java.util.Date d = new Date();
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "My server address");
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.smtp.port", "25");
Authenticator authenticator = new SmtpAuthenticator();
Session mailSession = Session.getDefaultInstance(props, authenticator);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress("My email"));
message.setSubject("Voicemail Notification");
message.setContent("You are receiving this automatic message because there has been a voicemail left in the system on " +d.toString() + " for the division of the company you work for. \n" +
"Please respond promptly. Thanks!\n" +
"Private Ip address?file=" + messageName + ".gsm", "text/plain");
message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailTo));
transport.connect();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
System.out.println("Email Sent!");
}
catch(Exception ex)
{
ex.printStackTrace();
System.out.println("Unable to send email notification to: " + emailTo);
}