請問 javamail 傳送程式編譯問題

hyb發表於2008-02-17

同樣的程式在jdk1.4 下可以編譯執行 但jdk1.5下不能編譯
public class Send
{
public static void main(String args[]) throws Exception
{

String host = "smtp.sohu.com";
String from = "aaa@sohu.com";
String to = "aaa@hotmail.com";
String username = "aaa";
String password = "1223456";

// Get system properties
// Properties props = System.getProperties();
Properties props = new Properties();

// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");

// Get session
Session session = Session.getDefaultInstance(props);

// watch the mail commands go by to the mail server
session.setDebug(true);

// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");

// Send message
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}



}


丟擲異常如下:
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Exception in thread "main"

相關文章