[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-developers] Need help with tomcat.policy with Javamail



Hi Jack,

 You'll need to give more permission to the servlet. Create a file called:

  /usr/java/jakarta-tomcat/conf/tomcat.policy.custom

  Put in the following line:

 permission 
java.net.SocketPermission"localhost:1024-","connect,accept,listen,resolve";

  This should do the trick. If not, and you're sure you trust all the
servlets running on your machine,  you can give the servlet full permissions
by adding:

  permission java.security.AllPermission;

 to tomcat.policy.custom.

_Tim

On 7/16/01 10:48 AM, "jack.chu@xxxxxxxxxxx" <jack.chu@xxxxxxxxxxx> wrote:

> 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 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
> 
> 
> 
> _______________________________________________
> cobalt-developers mailing list
> cobalt-developers@xxxxxxxxxxxxxxx
> http://list.cobalt.com/mailman/listinfo/cobalt-developers
>