JavaMail -- Applet

Hello,
the "msgsend.java" code from JavaMail 1.3.2 from Sun is obviously not a code for using with an Applet. As I want to create a GUI for the JavaMail, I need to write/transform the code.
My problem is to transform this part
" for (optind = 0; optind < argv.length; optind++) {
     if (argv[optind].equals("-T")) {
          protocol = argv[++optind];
     } else if (argv[optind].equals("-H")) {
          host = argv[++optind];
     } else if (argv[optind].equals("-U")) {
          user = argv[++optind];
     } else if (argv[optind].equals("-P")) {
          password = argv[++optind];
     } else if (argv[optind].equals("-M")) {
          mailhost = argv[++optind];
     } else if (argv[optind].equals("-f")) {
          record = argv[++optind];
     } else if (argv[optind].equals("-s")) {
          subject = argv[++optind];
     } else if (argv[optind].equals("-o")) { // originator
          from = argv[++optind];
     } else if (argv[optind].equals("-c")) {
          cc = argv[++optind];
     } else if (argv[optind].equals("-b")) {
          bcc = argv[++optind];
     } else if (argv[optind].equals("-L")) {
          url = argv[++optind];
     } else if (argv[optind].equals("-d")) {
          debug = true;
     } else if (argv[optind].equals("--")) {
          optind++;
          break;
     } else if (argv[optind].startsWith("-")) {
          System.out.println(
"Usage: msgsend [[-L store-url] | [-T prot] [-H host] [-U user] [-P passwd]]");
          System.out.println(
"\t[-s subject] [-o from-address] [-c cc-addresses] [-b bcc-addresses]");
          System.out.println(
"\t[-f record-mailbox] [-M transport-host] [-d] [address]");
          System.exit(1);
into an Applet.
The problem is, if I have different textfields for Host, Email Subject, Email to/from etc... I do not know how I can put these information together to have an executed code, like now in MSDOS "java msgsend -o email@from -M host email@to".
Can you help me? Perhaps send a prototyp?

Is your applet signed properly? Note that you have to sign all the jars for the applet -- including the JavaMail jar and the activation jar -- using the same signer.

Similar Messages

  • JavaMail Applet with sending attachment

    hello everybody,
    Do u have any samples about sending attachment by using JavaMail Applet?
    You will be very appreciated if u can send me the Java source code.
    Thanks very much!
    Best rgds.~
    Alpha

    If you are going to run this from a webpage I would suggest that you change your approach and look into doing this server side. The security restrictions placed on applets will cause all kinds of problems. Just to name two:
    1. An applet can only communicate with the server it came from. This means that the SMTP server and the web server must be on the same machine.
    2. An applet cannot access the file system on the local machine. Just imagine the security holes that would be there if it could.
    One solution for these problems is to sign the applet, but after working on this approach for several days I decided to do everything with servlets instead.

  • JavaMail applet working on local machine - but NOT on my webpage

    Hi.
    My code works on my machine as an applet run through my Eclipse IDE.
    I have the Applet deployed on my website, which is the same server as the email server itself.
    public void postMail(String to, String subject,
                                String message , String from) throws MessagingException
        boolean debug = false;
         //Set the host smtp address
         Properties props = new Properties();
         props.put("mail.smtp.host", "mail.completemusician.net");
         props.put("mail.smtp.port", "2626");
         props.put("mail.smtp.auth", "true");
        Authenticator auth = new SMTPAuthenticator();
        Session session = Session.getDefaultInstance(props, auth);
        session.setDebug(debug);
        // create a message
        Message msg = new MimeMessage(session);
        // set the from and to address
        InternetAddress addressFrom = new InternetAddress(from);
        msg.setFrom(addressFrom);
        InternetAddress addressTo = new InternetAddress(to);
        msg.setRecipient(Message.RecipientType.TO, addressTo);
        // Setting the Subject and Content Type
        msg.setSubject(subject);
        msg.setContent(message, "text/plain");
        Transport.send(msg);
    }1) I know my code works on my local machine - so it's not related to a code bug.
    2) I know that all class files are uploaded correctly and working in a single JAR file. The other 3 classes I use work fine in this applet.
    3) I receive no errors of any kind - it just appears that my constructor may not be called, or the instant java mail API is mentioned, the applet just refuses to work.
    v.setMessage("Attempting to send..");This line never is used in my class constructor - which is troubling.
    public SendMailUsingAuthentication(String from, String to, String subject,
              String text, ValidationDialog vd) {
           v = vd;
           v.setMessage("Attempting to send..");
           boolean succeed = true;
           try {
              postMail(to, subject, text, from);
         } catch (Exception e) {
              // TODO Auto-generated catch block
              v.setMessage("Email delivery has failed. " +
                         "Please check your email address provided and try again." +
                         "\n\n" + e.getMessage());
              e.printStackTrace();
              succeed = false;
         if(succeed)
               v.setMessage("Your request has been submitted successfully.\n\n" +
                         "You may safely navigate away from this page.");
               v.setBlue();
         // TODO Auto-generated constructor stub
    }Feel free to reply - I would appreciate your help. Just keep in mind:
    1) Don't tell me to use javascript. I refuse.
    2) Don't tell me I need a server application. It's supposed to work according to documentation, without it.

    Is your applet signed properly? Note that you have to sign all the jars for the applet -- including the JavaMail jar and the activation jar -- using the same signer.

  • Javamail in applet

    Hi,
    I am trying to send a mail from a java applet using the javamail api.
    I've done a lot of homework since I'm new to java.
    I succeeded to create the applet which sends mail (not from the browser) and then I put it in a test html file.
    I read that this will not work since the applet needs to be signed.
    So I self-signed the applet and the mail.jar of javamail.(hopefully I did this stage correctly)
    Now when I open the applet the I'm asked to give a permission to run the applet.
    Unfortunately this still doesn't work!!!
    I still receive " access denied (java.net.SocketPermission smtp.gmail.com resolve)"
    I'm quite sure that this can be done.
    Any idea what am I doing wrong?

    I'm pretty sure gmail doesn't allow you to use it to send emails except using their own user interface.
    If they do, they're setting themselves up as a massive spam relay.

  • Here's how you use JavaMail in a Netscape 4.x applet

    First of all... Sun has said that they are working on patching JavaMail for the next minor release so that it will be usable with Netscape.
    But for those with itchy pants... here's how you do to send mail from a Netscape 4.x applet without using the Java Plug-in.
    First of all... you'll need to sign the applet. Now I'm not so good with singing tools so I don't know if Netscape 4.x allows using Sun's signing tools. I used Netscapes own "signtool" just to be sure.
    You'll need to unjar activation.jar and mail.jar (or mailapi.jar plus smtp.jar). Use signtool to sign and jar your own classfiles plus those from the jar-files mentioned.
    This creates a small problem though: atcivation.jar and mail.jar has files in the META-INF directory. Netscapes signtool ignores these files. So you'll have to patch around that.
    Using the "sendfile.java" demo as basis... here's how you deal with the missing configuration files.
        // You'll have to request this privilige or Netscape will bolt on you.
        // If you need cross-platfor compatibility you'll need to wrap this up or IE
        // will be really cranky at this. Try by doing something you know
        // IE accepts but that Netscape don't. Catch the  exception as just an
        // Exception and do the following in the catch.
        try {
          PrivilegeManager.enablePrivilege("UniversalPropertyRead");
        } catch (netscape.security.ForbiddenTargetException e2) {
          System.out.println("Failed! Permission to read system properties denied by user.");
        } catch (Exception e2) {
          System.out.println("Failed! Unknown exception while enabling privilege.");
          e2.printStackTrace(System.out);
        // create some properties and get the default Session
        Properties props = null;
        props = System.getProperties();
        props.put("mail.smtp.host", mailhost);
        // The mailcap command map needs a missing
        // config file. So you'll have to hardwire the different
        // commands like this.
        javax.activation.MailcapCommandMap commandMap = new javax.activation.MailcapCommandMap();
        commandMap.addMailcap("text/plain;;          x-java-content-handler=com.sun.mail.handlers.text_plain");
        commandMap.addMailcap("text/html;;          x-java-content-handler=com.sun.mail.handlers.text_html");
        commandMap.addMailcap("text/xml;;          x-java-content-handler=com.sun.mail.handlers.text_xml");
        commandMap.addMailcap("multipart/*;;          x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
        commandMap.addMailcap("message/rfc822;;     x-java-content-handler=com.sun.mail.handlers.message_rfc822");
        commandMap.addMailcap("image/gif;;          x-java-view=com.sun.activation.viewers.ImageViewer");
        commandMap.addMailcap("image/jpeg;;          x-java-view=com.sun.activation.viewers.ImageViewer");
        commandMap.addMailcap("text/*;;          x-java-view=com.sun.activation.viewers.TextViewer");
        commandMap.addMailcap("text/*;;          x-java-edit=com.sun.activation.viewers.TextEditor");
        javax.activation.MailcapCommandMap.setDefaultCommandMap(commandMap);
        // Now here is a really weird thing. This class - MimeUtility - will
        // be used later on. But the ClassLoader in Netscape seems
        // to be broken. I downloaded J2EE and fiddled with this class a bit.
        // It seems that the following line will get you around this problem.
        Object o = MimeUtility.class;
        try {
          // create a message
          Session session = Session.getDefaultInstance(props, null);
          session.setDebug(true);
          MimeMessage msg = new MimeMessage(session);
          msg.setFrom(new InternetAddress(from));
          InternetAddress[] address = {new InternetAddress(to)};
          msg.setRecipients(Message.RecipientType.TO, address);
          msg.setSubject("Message from scratchpad");
          // create and fill the first message part
          MimeBodyPart mbp1 = new MimeBodyPart();
          mbp1.setText(message);
          // create the second message part
          MimeBodyPart mbp2 = new MimeBodyPart();
          // attach the file to the message
          // This is not the same as the original.
          // The ByteArrayDataSource class helps you attach an arbitrary file-type.
          // The code for that is found here:
          // http://forums.java.sun.com/thread.jsp?forum=43&thread=73819
          DataSource ds = new ByteArrayDataSource(imageData, "image/gif", "image.gif");
          mbp2.setDataHandler(new DataHandler(ds));
          mbp2.setFileName("image.gif");
          // create the Multipart and its parts to it
          Multipart mp = new MimeMultipart();
          mp.addBodyPart(mbp1);
          mp.addBodyPart(mbp2);
          // add the Multipart to the message
          msg.setContent(mp);
          // set the Date: header
          msg.setSentDate(new Date());
          // send the message
          // Transport.send() will give you exception in Netscape.
          // Here is how you do what that method does.
          msg.saveChanges();
          com.sun.mail.smtp.SMTPTransport transport = new com.sun.mail.smtp.SMTPTransport(session, null);
          transport.connect();
          transport.sendMessage(msg, address);
          transport.close();     
        catch (MessagingException mex) {
          mex.printStackTrace();
          Exception ex = null;
          if ((ex = mex.getNextException()) != null) {
            ex.printStackTrace();
        }Enjoy
    /Michael

    Typical... i knew I'd fumble. There is one more thing you need to do.
    Download J2EE, source code edition and patch the file javax.mail.internet.MimeUtility.java
    Change the line
    InputStream is = javax.mail.internet.MimeUtility.class.getResourceAsStream("/META-INF/javamail.charset.map");...to...
    InputStream is = javax.mail.internet.MimeUtility.class.getResourceAsStream("/javamail.charset.map");Also, after you unjar the jarfiles and before you run the signtool, move the file META-INF/javamail.charset.map to the partent of the META-INF directory.
    /Michael

  • JavaMail in applets

    Hi everyone.
    I can't seem to find a clear-cut answers anywhere out there.
    I have a client who wants a full email client embedded in her site. Obviously, if I wanted to get this working on the server, I would need the javamail and jaf jar files there, but where? Even if they're on the server, how do I tell my program where to find them?
    I don't have physical access to the server as she's using HostGator, but I do have ftp.
    I know this is possible, but I just can't find a good explanation or tutorial anywhere.
    Thanks a lot, I really appreciate the advice.

    evilfrenchguy wrote:
    Yes, you should be able to send and recieve to any address. The client would be tied to a single email address, so the login is from the same host.
    This is just a PHP file with an embedded applet for the client. I don't feel confident enough in my servlet and jsp experience to attempt it as a web app. Is that the only way?
    I apologize that I am just learning the JavaMail API. I'm thinking that the only thing I need to do to go from application to applet is find a way to get those two jars in the right spot with ftp in a spot where java can find it.To be honest, aside from a bit of form handling in JSP, the Java code won't be much different whether you use Javamail in an applet or a webapp. But I can see endless struggle ahead of you, for very unsatisfactory results. Here's what I'd do if I was you, and had a client who wanted "email in her site". Use Google apps for domains. Then users can have a full-blown Gmail account, with [email protected] Full-featured mail, much better than anything you'll be able to write. Or alternatively, what about using PHP for it? That'll give you hooks into sendmail, probably. Either way, an applet for mail is going to be too much hassle for a rubbish result, if it works at all.

  • While sending mail through applet

    Hi All,
    I have a problem while using the following code in my applet
    Here is the code i got the exception.
    public void postMail( String smtpHost, String recipients[], String subject,
    String message , String file, String from) throws MessagingException
    boolean debug = false;
    //Set the host smtp address
    Properties props = new Properties();
    props.put("mail.smtp.host", smtpHost);
    props.put("mail.smtp.auth", "true");
    Authenticator auth = new SMTPAuthenticator();
    Session session = Session.getDefaultInstance(props, auth);
    session.setDebug(debug);
    // create a message
    Message msg = new MimeMessage(session);
    // set the from and to address
    InternetAddress addressFrom = new InternetAddress(from);
    msg.setFrom(addressFrom);
    InternetAddress[] addressTo = new InternetAddress[recipients.length];
    for (int i = 0; i < recipients.length; i++)
    addressTo[i] = new InternetAddress(recipients);
    msg.setRecipients(Message.RecipientType.TO, addressTo);
    // Setting the Subject and Content Type
    msg.setSubject(subject);
    msg.setSentDate(new Date());
    if(!file.equals(""))
    BodyPart messageBodyPart = new MimeBodyPart();
    // Fill the message
    messageBodyPart.setText(message);
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    // Part two is attachment
    messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(file);
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName((new File(file)).getName());
    multipart.addBodyPart(messageBodyPart);
    msg.setContent(multipart);
    else msg.setContent(message, "text/plain");
    Transport.send(msg);
    ---->exception
    Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: javax/mail/MessagingException
    And -->
    Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: javax/mail/Authenticator
    i set the jar file mail.jar and activation.jar file in tomcat webserver
    webapp/ myproj/lib
    Can any one please help me???
    Thanks,
    Kiran

    The JVM can't find JavaMail or the JavaBeans Activation Framework (JAF) on the classpath.
    Assuming your applet is packaged in a JAR file, you'll need the "archive" attribute to specify not just your applet's JAR file but also the JavaMail and JAF JARs too, so all 3 get downloaded to the browser.
    <applet archive="your.jar,mail.jar,activation.jar" ... />
    Alternatively you can permanently install JavaMail and JAF on the client machine (PATH_TO_JRE/lib/ext folder).
    However, the default applet security policy won't allow connections to machines other than the one from which the applet was downloaded. You will have to change the policy on the client to allow SMTP connections. (To put it another way, if you do get the JavaMail/JAF classes sent to the browser, you'll get SecurityExceptions.)
    A better (?) way of doing this would be to have a servlet that the applet can make requests to, and have the server send the mail.

  • Suppressing Applet alerts when using java mail api

    Hi,
    Im using the following code to send email from my application. Im using JSF (tomahawk), Spring and hibernate in my application. I'm using spring email API classes to send email. This code works perfectly fine in the sense its parsing template and sending emails to the configured email id.
    I have defined this class as a managed bean and i have a commanButton is UI which is bound to this sendEmail() method
    <t:commandButton value="Send email" action= #{email.sendEmail}/>
    import java.io.StringWriter;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    import javax.mail.MessagingException;
    import javax.mail.internet.MimeMessage;
    import org.apache.velocity.Template;
    import org.apache.velocity.VelocityContext;
    import org.apache.velocity.app.VelocityEngine;
    import org.apache.velocity.exception.ParseErrorException;
    import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
    import org.apache.velocity.runtime.resource.util.StringResourceRepository;
    import org.springframework.mail.MailException;
    import org.springframework.mail.SimpleMailMessage;
    import org.springframework.mail.javamail.JavaMailSenderImpl;
    import org.springframework.mail.javamail.MimeMessageHelper;
    import au.gov.nsw.railcorp.onlineticketing.external.model.request.ServiceFees;
    public class EmailService {
         JavaMailSenderImpl sender;
         VelocityEngine engine;
         public EmailService(){
         sender = new JavaMailSenderImpl();
             sender.setHost("<smtp ip>");
             sender.setPort(25);
             sender.setUsername("<user id>");
             sender.setPassword("<password>");
             engine = new VelocityEngine();
             Properties p = new Properties();
             p.setProperty("resource.loader", "string");
             p.setProperty("string.resource.loader.class",
                  "org.apache.velocity.runtime.resource.loader.StringResourceLoader");
             try {
                   engine.init(p);
              } catch (Exception e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         public VelocityEngine getEngine() {
              return engine;
         public void setEngine(VelocityEngine engine) {
              this.engine = engine;
         public JavaMailSenderImpl getSender() {
              return sender;
         public void setSender(JavaMailSenderImpl sender) {
              this.sender = sender;
         public static void main(String args[]){
              EmailService emailService=new EmailService();
              emailService.sendEmail();
         public boolean sendEmail(){
         try{
                 MimeMessage message = sender.createMimeMessage();
                 MimeMessageHelper helper = new MimeMessageHelper(message);
                 helper.setTo("<to email id>");
                 helper.setFrom("<from email id>");
                 helper.setSubject("Teting velocity");
                 VelocityContext context = new VelocityContext();
                 StringWriter writer =  new StringWriter();
                 Template template =new Template();
                    StringResourceRepository repository =StringResourceLoader.getRepository();
                    String tempText="<html><body>Hi, ${username}...<p> this is a some template!</p></body></html>";
                 repository.putStringResource("myTemplate",tempText );
                 context.put("username", "Marc");
                 template = engine.getTemplate("myTemplate");
                  template.merge(context, writer);
                  System.out.println("VM Template:\n" + tempText);
                  System.out.println("Output:\n" + writer);
                  String body=writer.toString();
                  helper.setText(body,true);
                  sender.send(message);
            catch (MessagingException ex) {
                // simply log it and go on...
                System.err.println(ex.getMessage());           
            catch (MailException ex) {
                // simply log it and go on...
                System.err.println(ex.getMessage());           
            } catch (ParseErrorException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
         return true;
    }The problem i have is when i try to invoke the function sendEmail() from my UI it is throwing a series of applet alerts (some 10 of them) . The following are the alerts that i get
    1. The applet is attempting to invoke the java/lang/System.getProperty() operation on java.home
    2. The applet is attempting to perform a read operation on the file C:\Program Files\java\jre1.5.0_14\javamail.providers
    3. The applet is attempting to perform a read operation on the file C:\Program Files\java\jre1.5.0_14\javamail.address.map etc....
    For ever applet alert i had to click on 'allow' for it to proceed. But there is no problem in sending mail after that. One more interesting this is i DONT get this alert when i try to execute this java class directly instead of calling the method from another class or from UI.
    Can someone please let me know the reason for this applet alert and the way to suppress it?
    Its really urgent .. please help
    Thank you..

    Hi Subhadip,
    Thanks for the quick response :)
    Please help me understand this.. Im not explicitly using applet anywhere .I guess it should be used internally by one or many of the API classes i have used . In this scenario how can self sign the applet and which one?
    I have included some jars like activation.jar,mail-1.4.2.jar,velocity-1.6.2.jar in my webapp lib . Is there a means to sign these jars and use? Is this what you are suggesting me to do?
    One more doubt i have is how come the same method runs without any problem when executed as a standalone java class (with main() method)
    Will be really helpful if you could help me understand this...
    Thanks,
    Swami

  • Need to setup javamail for testing

    Hi team, I am new to Java. I am not able to compile javamail application. I download javamail-1.4.1 and jaf-1.0.2 under c:\.
    I was update a classpath like this.
    .;C:\j2sdk1.4.2_16\bin;c:\javamail-1.4.1\mail.jar;c:\jaf-1.0.2\activation\activation.jar.
    Here is my program
    public static void main(String[] args) {
    // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
    String to = "[email protected]";
    String from = "[email protected]";
    // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
    String host = "mail.yahoo.com";
    // Create properties, get Session
    Properties props = new Properties();
    // If using static Transport.send(),
    // need to specify which host to send it to
    props.put("mail.smtp.host", host);
    // To see what is going on behind the scene
    props.put("mail.debug", "true");
    Session session = Session.getInstance(props);
    try {
    // Instantiatee a message
    Message msg = new MimeMessage(session);
    //Set message attributes
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address = {new InternetAddress(to)};
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject("Test E-Mail through Java");
    msg.setSentDate(new Date());
    // Set message content
    msg.setText("This is a test of sending a " +
    "plain text e-mail through Java.\n" +
    "Here is line 2.");
    //Send the message
    Transport.send(msg);
    catch (MessagingException mex) {
    // Prints all nested (chained) exceptions as well
    mex.printStackTrace();
    }//End of class
    When i compile this program i am getting below message
    C:\Documents and Settings\Administrator\Desktop\Applet>javac TestEmail.Java
    javac: invalid flag: TestEmail.Java
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing
    -deprecation Output source locations where deprecated APIs are used
    -classpath <path> Specify where to find user class files
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -d <directory> Specify where to place generated class files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release
    -target <release> Generate class files for specific VM version
    -help Print a synopsis of standard options
    Please suggest and correct me on this.
    Thanks in Advance

    Hopefully it was clear from the error message that javac didn't even try to
    compile your program. Perhaps you need to name your file "TestEmail.java"
    instead of "TestEmail.Java"?
    Also, if you're still using JDK 1.4.2, it's way past time to upgrade. JDK 1.6 has
    been available for a long time. And you don't need the JDK directory in your
    CLASSPATH.
    Finally, double check that the mail.jar and activation.jar files exist at the
    locations you used in your CLASSPATH. That's not your current problem,
    but it will be important later.

  • JRE 1.4.x Plugin - Signed Applets and Weird Behaviour (Policy)

    Hello.
    I have recently experienced some strange behaviour related to signed applets and policy files in JRE 1.4.2-b28 ( a friend got the same behaviour in a flavour of 1.4.1-xx as well ). Both tests were on Windows 2000 Professional platforms.
    Initially my unsigned applet, which attempts socket connections to a server different from the download location, fails with security exceptions ( as expected ). Then I did the following to sign the applet jar and configure my environment
    Steps: 1) Import "trusted CA" certificate into ${java.home}/lib/security/cacerts. (JRE home outside the JDK)
    2) Signed the jar using jarsigner and a certificate generated from the "trusted CA" (Entrust CA and certificate).
    3) Imported the signing certificate into the Java plugin using import in the plugin control panel.
    4) Created a new keystore (keytool,jks) and imported the signing certificate into the keystore with alias "developer". The keystore is stored in the user home as .keystore.
    5) Created a .java.policy for the user and attaching the keystore in 4) to it. ( also stored in user home ).
    6) Used the policy tool to grant socketpermissions to the specific codebase ( testing with file:/C:/test/* initially ) signed by "developer"
    After this, when I ran the test page under IE 5.5SP2 and Netscape 7.1 it worked without any security exception. Ditto for using the appletviewer and the policy file I created for the user.
    The weird part occurred when I removed the policy entry from the user policy file. After doing this, Netscape and IE still allow the applet to execute - somehow remembering that it was granted permissions at some point. The appletviewer does not allow it to execute, generating security exceptions.
    It appears the old policy is being cached somewhere, but I cannot find where. If I replace the applet jar with an unsigned version it does fail in IE and Netscape. I tried cleaning the plugin cache and removing the "deployment.certs" files related to the users but still get the same behaviour.
    Does anyone know where the old policy information is being stored ? Does anyone know how to revoke the permissions so that I am restored to my original base environment ( no permissions for "designer" signed applets ) ? Would attempting to utilize the AccessController.doPriveleged( xxxx ) operations in JDK 1.4 avoid all of this confusion with policy files, keystores and certificate storage ? After all the messing about I would like a zero-footprint alternative ( or minimzed footprint anyway ).
    Any ideas would be most welcome.
    Regards,
    James.

    Hello Again.
    I am either enlightened or confused at this point. I found that as long as all of my related Jars are signed ( even by self-signed certificates ) I am granted SocketPermissions for calls outside of the originating server. Unsigned code is refused, but even when the Jars were signed using a self-signed certificate the Socket calls were allowed.
    Am I experiencing the appropriate behaviour in this case ( which would mean not having to utilize policy files to distribute an applet that uses calls to arbitrary servers - e.g. JavaMail ) or am I suffering from something damaged in my environment ?
    It has been a long time since I played with signed applets and I am having difficulty determining what operations require policy file entries/AccessController.doPrivileged() calls and which are granted when a user elects to trust a signed applet without policy.
    Any assistance in clearing up my confusion would be appreciated.
    Regards,
    James.

  • JAVAMAIL again...

    Hi Developer.
    If just go on writing some Applets to send email. Using SDK 1.4.1, NB 3.6, JAVAMail 1.3.1 and SAF 1.0.2 I just cant send mail, because...
    ...IOException while copying message;
    javax.activation.UnsupportedDataTypeException: no object DCH for mime type text/plain
    at javax.mail..internet.MimeMessage.<init>(MimeMessage.java:205)
    I've searched the archive, finds a lot of entryies, but no help. So I tried it again with these actual source:
    public void RTK_sendMail(String body, String subject, String sender, String to, String copy) {
    String server = "mail.mydomain.com";
    Properties props = new Properties();
    props.put("mail.smtp.host", server);
    Session session = Session.getDefaultInstance(props, null);
    try {
    InternetAddress from = new InternetAddress(sender);
    InternetAddress[] address = {new InternetAddress(to)};
    InternetAddress[] replyto = {new InternetAddress(sender)};
    Object objBody = new String(body);
    MimeMessage msg = new MimeMessage(session);
    // Multipart mp = new MimeMultipart();
    // MimeBodyPart mbp = new MimeBodyPart();
    msg.setFrom(from);
    msg.setReplyTo(replyto);
    if (copy != null) {
    msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(copy, false));
    msg.setSubject(subject, "us-ascii");
    msg.setSentDate(new java.util.Date());
    msg.setHeader("X-Mailer", "JavaClient/Applet Order-1.000-04/2004");
    DataHandler myData = new DataHandler(objBody, "text/plain");
    msg.setDataHandler(myData);
    com.sun.mail.smtp.SMTPTransport transp = new com.sun.mail.smtp.SMTPTransport(session, new URLName("SMTP", server, -1, "mail", null, null));
    com.sun.mail.smtp.SMTPMessage smtpMsg = new com.sun.mail.smtp.SMTPMessage(msg);
    transp.connect();
    transp.sendMessage(smtpMsg, address);
    catch (MessagingException mex) {
    mex.printStackTrace();
    I've controlled the seqence in the NB-CLASSPATH during compiletime and I think it's ok. The mail server is the same server, where the Applet is at home. I do not now, how I could manipulate the Applet load sequence... If I look into the classloader list, I see javax.mail...., some other classes, my Applet class - but, I can't find any javax.activation class???
    So, I that is wrong?

    Additional not:
    IAfter the initial load of the applet, some javax.mail... class are loaded and no javax.activiation classes. If I press on the button to start send an email, al large number of javax.mail classes and javax.activation classes are loaded in a non-sorted sequence.
    Cause that my trouble???

  • Email,Applets and Result

    I have designed a web page with an applet.Users give input
    to the applet and it produces some results.I have been told
    i cannot save on the users hard disk because applets do not
    allow it but is there a way to send,the result and input, to the
    user via email.Someone told me there are on-line chess games
    that do this.Does anybody know how to do this?
    Thank you
    P.S:i am new to JAVA so please bear with me

    By default, an applet can only open sockets to the site it was loaded from. So perhaps you should run a program on your server which the applet connects to, and get this program to use the JavaMail API to send mail. (Or use RunTime.Exec calls to sendmail on a UNIX system).

  • Send email through applet

    Hello!
    Can anyone give me simple code of applet where i can send email through the form... and jar files or anything i have to import...
    Thank you very much

    Depends on how you want to handle it.
    If you want to send an email from the User's email program, you can execute a simple http request to "mailto:[email protected]" from within the applet by calling
    Applet.getAppletContext().showDocument("mailto:[email protected]")This will cause an email window to pop up using the user's email client.
    However, if you want to send email from within your program directly then you get into an area that is a little more complicated.
    First you would be using the javax.mail API. http://java.sun.com/products/javamail
    The problem you would have with this is that as an Applet you can only connect back to the server from which you came. So that server MUST have an SMTP process running on it. Otherwise you cannot send mail out since an Applet is not allowed to contact any other server other than it's own.
    If that security restriction is not a problem, then the example code at http://developer.java.sun.com/developer/onlineTraining/JavaMail/ should do everything you need.

  • Send an email for an Applet....please help ..

    hello guys...
    i have an applet that works much like an HTML form...
    it is a form for products and after having filled that the information has to be updated to the database and the concern people of the company should get an email for the same ....
    how can i send that mail from this Applet... !?!?
    hope someone has some idea about it.. !!!
    please help..

    You should be able to use JavaMail from an applet. The general outline would be the same as from a stand-alone application. However make sure you read the notes (found in %JAVAMAIL_HOME%/NOTES.txt once you install JavaMail) to know about some issues associated with using JavaMail from applets running certain browsers.

  • Email applet

    could anyone tell me a way to send an email from an applet.
    regards
    fightspam

    The same way you'd do it from any other Java app:
    http://java.sun.com/products/javamail/
    but you're going to run into security issues and you'll probably need to sign the applet.

Maybe you are looking for