2011-12-14 5 views
3

から呼び出されます。電子メールはアクティベーションコードで構成されています。は、電子メールを送信するためにクラスを設定する支援が必要、それは私は、ユーザーが最初にログインしたときに自分のアプリケーションから電子メールを送信しようとしていますメインクラス

アップデート:私は、最新のJavaMail APIをダウンロードし、また、最新のJAF(JavaBeansの起動フレームワーク)と、それは未知のシンボルであること輸入のためにコンパイルされません。 javaxパッケージからインポートするにはどうすればいいですか?ここで

は、私がこれまでに得たコードは次のとおりです。ここで

import java.util.ArrayList; 
import javax.mail.Message; 
import javax.mail.MessagingException; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.AddressException; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage; 

public class Email { 
    static String smtpHost; 
    static int smtpPort; 
    static String from; 
    static String to; 
    static String subject; 
    static String content; 

    public Email(String toEmail, String code){ 
     smtpHost = "localhost"; 
     smtpPort = 25; 
     from = "[email protected]"; 
     to = toEmail; 
     subject = "Hello from Nestroia.com"; 
     content = "This is your activation code: " + code; 
    } 

    public Email(String toEmail, String name, String password){ 
     smtpHost = "localhost"; 
     smtpPort = 25; 
     from = "[email protected]"; 
     to = toEmail; 
     subject = "Hello from Nestroia.com"; 
     content = "This is your Login information.\n" 
       + "Name: " + name + "\n" 
       + "Password: " + password;   
    } 

    public static void send() throws AddressException, MessagingException { 

     // Create a mail session 
     java.util.Properties props = new java.util.Properties(); 
     props.put("mail.smtp.host", smtpHost); 
     props.put("mail.smtp.port", ""+smtpPort); 
     Session session = Session.getDefaultInstance(props, null); 

     // Construct the message 
     Message msg = new MimeMessage(session); 
     msg.setFrom(new InternetAddress(from)); 
     msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); 
     msg.setSubject(subject); 
     msg.setText(content); 

     // Send the message 
     Transport.send(msg); 

は、スタックトレースです:

java.lang.RuntimeException: java.lang.ClassFormatError: Absent Code attribute in  method that is not native or abstract in class file javax/mail/Address 
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source) 
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source) 
at com.sun.glass.ui.View.notifyMouse(Unknown Source) 
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source) 
at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source) 
at java.lang.Thread.run(Thread.java:722) 
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/Address 
at java.lang.ClassLoader.defineClass1(Native Method) 
at java.lang.ClassLoader.defineClass(ClassLoader.java:791) 
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) 
at java.net.URLClassLoader.access$100(URLClassLoader.java:71) 
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) 
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:423) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
at Nestroia.Nestroia_Main$6$1.handle(Nestroia_Main.java:669) 
at Nestroia.Nestroia_Main$6$1.handle(Nestroia_Main.java:559) 
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source) 
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source) 
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source) 
at javafx.event.Event.fireEvent(Unknown Source) 
at javafx.scene.Node.fireEvent(Unknown Source) 
at javafx.scene.control.Button.fire(Unknown Source) 
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source) 
at com.sun.javafx.scene.control.skin.SkinBase$5.handle(Unknown Source) 
at com.sun.javafx.scene.control.skin.SkinBase$5.handle(Unknown Source) 
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source) 
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source) 
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) 
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source) 
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source) 
at javafx.event.Event.fireEvent(Unknown Source) 
at javafx.scene.Scene$MouseHandler.process(Unknown Source) 
at javafx.scene.Scene$MouseHandler.process(Unknown Source) 
at javafx.scene.Scene$MouseHandler.access$1300(Unknown Source) 
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source) 
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source) 
... 7 more 
+1

ここでの質問は何ですか?あなたは例外を取得していますか? –

+0

私は例外を取得しています。それは私が電子メールを送信することを許可しない、それは私が投稿した理由です。すぐに発見できるコードに何か問題はありますか? –

+3

次に例外を貼り付けてください...鮮明な画像が表示されます.. –

答えて

3

私は、あなたはおそらく、あなたのクラスパスにちょうどjavaee.jarを持って推測されていますjavax.mail。*クラスの定義はありますが、実際の実装はありません。

すでに持っていけない場合は、JavaMailのAPIをダウンロードしてください。 here

+0

ありがとうございました –

+0

チャンスが来たら更新を見てください –

2

見つかりあなたは実装が含まれていませんjavaee.jarで実行しています。実行するのではなく、コンパイルを有効にすることを目的とした、「スタブ」された実装です。このpostは詳細を提供します。 (これはJava EE 5を参照することですが、同じことが6についても同様)

+0

ありがとうございました。 –

+0

チャンスが訪れたら更新を見てください –

0

This post説明と可能な解決策を提供します。クラスパスを調整する必要があるかもしれません。

関連する問題