We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Processing applet + javaMail library wont work
Page Index Toggle Pages: 1
Processing applet + javaMail library wont work (Read 2767 times)
Processing applet + javaMail library wont work
Mar 30th, 2010, 4:10pm
 
Hello, im trying to develop an applet that uses the javaMail library, but i havent been able to get it work. It works well when i run it as a desktop application but the problem comes when i export it as an applet and then try to execute the sending email modules, i just tried it with a simple example and figured out the problem was with that library.

Heres the example i used. (After pressing a key the applet wont work anymore)

import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import java.util.Properties;

void setup() {
 size(640, 480);
 background(0);
}

void draw() {
 if(mousePressed)
   background(random(255));
}

void keyPressed() {
 try {
   new SimpleMail().send();  
 }catch(Exception e){}
 
}


class SimpleMail {

   private static final String SMTP_HOST_NAME = "smtp.domain.com";
   private static final String SMTP_AUTH_USER = "myemail@mydomain.com";
   private static final String SMTP_AUTH_PWD  = "mypassword";

   public void send() throws Exception{
       Properties props = new Properties();
       props.put("mail.transport.protocol", "smtp");
       props.put("mail.smtp.host", SMTP_HOST_NAME);
       props.put("mail.smtp.auth", "true");
       props.put("mail.smtp.starttls.enable","true");

       Authenticator auth = new SMTPAuthenticator();
       Session mailSession = Session.getDefaultInstance(props, auth);
       Transport transport = mailSession.getTransport();

       MimeMessage message = new MimeMessage(mailSession);
       message.setSubject("Subject");
       message.setContent("content", "text/plain");
       message.setFrom(new InternetAddress("myemail@mydomain.com"));
       message.setRecipient(Message.RecipientType.TO,
            new InternetAddress("email@domain.com"));
       transport.connect();
       transport.sendMessage(message,
           message.getRecipients(Message.RecipientType.TO));
       transport.close();
   }
   
    private class SMTPAuthenticator extends javax.mail.Authenticator {
       public PasswordAuthentication getPasswordAuthentication() {
          String username = SMTP_AUTH_USER;
          String password = SMTP_AUTH_PWD;
          return new PasswordAuthentication(username, password);
       }
    }
}


hope u can help me. thx
Re: Processing applet + javaMail library wont work
Reply #1 - Mar 31st, 2010, 1:21am
 
You probably need to sign the applet to send e-mail from an applet (because it can send sensitive information or be abused to send spam or such).
Re: Processing applet + javaMail library wont work
Reply #2 - Mar 31st, 2010, 7:23am
 
hello philho, thanks for ur reply

I signed my applet but it stills doesnt work Sad

thank you anyways
Re: Processing applet + javaMail library wont work
Reply #3 - Mar 31st, 2010, 7:31am
 
Well, you should look at the Java console to see if there are any errors.

Side note: using an applet to send e-mail isn't a very good idea because one can open your jar file and examine the .class files to find out your account information...
Re: Processing applet + javaMail library wont work
Reply #4 - Mar 31st, 2010, 8:25am
 
philho thx again.

Enabling the java console was usefull cause it showed me an exception here it is:

Exception in thread "Animation Thread" java.lang.NoClassDefFoundError: javax/mail/Authenticator
     at dragItems$GeneradorCotizaciones.enviarCotizacion(dragItems.java:597)
     at dragItems.mouseClicked(dragItems.java:150)
     at processing.core.PApplet.handleMouseEvent(Unknown Source)
     at processing.core.PApplet.dequeueMouseEvents(Unknown Source)
     at processing.core.PApplet.handleDraw(Unknown Source)
     at processing.core.PApplet.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.mail.Authenticator
     at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     ... 7 more

Why it says it doesnt find that class, doesnt the processing exporter do it for me? i mean including dependences etc? thank you


Edit: I solved that exception problem adding manualy the jar related to javaMail library into the html code, the applet doesnt crash anymore but it doesnt send emails also lol
Re: Processing applet + javaMail library wont work
Reply #5 - Mar 31st, 2010, 9:21am
 
Hello

my applet is now sending emails Cheesy, i had to sign the applet once i solved the dependences problems cause java console was saying me that

access denied (java.net.SocketPermission smtp.gmail.com resolve)

Thank you so much!
Page Index Toggle Pages: 1