2
我試圖使用NetBeans中的JavaMail的功能,但不斷收到錯誤在NetBeans錯誤使用JavaMail
javax.mail.MessagingException: Could not connect to SMTP host: 10.101.3.229, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
我使用的代碼是:
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class TESTINGemail {
public static void main(String [] args)
{
String to = "[email protected]";
String from = "[email protected]";
String host = "localhost";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("This is the Subject Line!");
message.setText("This is actual message");
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
我使用的教程,這基本上是他們使用的代碼。我試圖改變主機,但每次都失敗。
JavaMail常見問題[調試連接問題的提示](http://www.oracle.com/technetwork/java/javamail/faq/index.html#condebug)。 –