You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ja...@icarian.com on 2001/07/16 20:51:34 UTC

Need help with tomcat.policy and javamail

Hi,
 
I have a java servlet sending a email via smtp using JavaMail. The servlet
sends out the email fine when executed through telnet session. When I run
the servlet thru Tomcat, I get a java.security.AccessControlException:
access denied (java.net.SocketPermission stage.icarian.com resolve) error.
I'm running this on a cobalt server.
 
I'm assuming it's a security manager problem. I may be wrong. I need to know
how to configure the tomcat.policy.custom file to fix this problem.
 
The servlet code:
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
 
public class Mailer {
 
  private String host = "stage.icarian.com";
  private String to;
  private String from;
  private String subject;
 
  public Mailer(String to, String from, String subject) {
    this.to = to;
    this.from = from;
    this.subject = subject;
  }
 
  public void send() {
    Properties props = new Properties();
    props.setProperty("mail.smtp.host",host);
    Session s = Session.getInstance(props,null);
    try {
      MimeMessage msg = new MimeMessage(s);
      msg.setFrom(new InternetAddress(from));
      msg.addRecipient(msg.RecipientType.TO, new InternetAddress(to));
      msg.setSubject(subject);
      msg.setText("");
      Transport transport = s.getTransport("smtp");
      transport.connect();
      transport.send(msg);
 

//      Transport.send(msg);
    } catch (MessagingException mex) {
      mex.printStackTrace();
    }
  }

 
My tomcat.policy file
grant codeBase "file:/home/sites/site4/web/-" {
  permission java.net.SocketPermission "localhost:1024-", "listen,connect";
  permission java.util.PropertyPermission "*", "read,write";
  permission java.lang.RuntimePermission "accessClassInPackage.sun.io";
  permission java.io.FilePermission "-", "read,write,delete";
};
 
Thanks for any help.
Jack