0
這個錯誤正在使我瘋狂。我試圖在我的應用程序拋出異常時發送自己的電子郵件,但我剛剛開始出現此錯誤。我能夠成功ping主機,並且在使用nslookup時我可以獲得本地ip地址。有任何想法嗎?由於Java電子郵件例外 - 無法連接到SMTP主機
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);
}
你可以使用telnet連接到'telnet mailserver 25'嗎? –
@MitchDempsey,你應該添加你的評論作爲答案,我會接受它。我犯了一個愚蠢的錯誤。跳過槍併發布了一個問題,但你的評論幫助。謝謝 – tier1
好的,添加爲答案。 –