dcsimg
Java Mail Session Problem
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sriram_Kanala
Posted On:   Saturday, July 19, 2003 06:41 AM


I am using JavaMail to send an email. And my application is running on JBoss.



When I send the email for the first time, it's working fine. But from second mail onwards, it's showing



"SecurityException - Access to default session denied".



If I restart JBoss server, then again it's working fine for the first time ONLY. For the second mail, again it's the same problem.



What could be the reason?

Re: Java Mail Session Problem

Posted By:   Sriram_Kanala  
Posted On:   Saturday, July 19, 2003 06:52 AM

The code I'm using to post mail is:



public void postMail(String recipients[ ], 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", SMTP_HOST_NAME);
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[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);


// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);

}

About | Sitemap | Contact