Self signed Applet - still getting Security Exception...
Hi everyone...
I m new to Java Mail... Nd I m developing aApplet to send mail from my Gmail account, nd I usedkeytool, jarsigner toSelf sign the applet. NdI wrote a Html page and when calling my applet method using javascript, I m having Security Exception... And I m using Java 1.5 (i.e., J2SE 5)
Here is the sample of my code...
MyMail.java --
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
And all neccessory packages are imported....
public class MyMail extends JApplet
{
String server = "smtp.gmail.com";
String username;
String password;
String fromAddres="";
String toAddres="";
Other Variable declaration goes here........
Session ses;
Transport tr;
MimeMessage msg;
public void init() //For testing purpose
{
doLogin("username","password"); //My account details
}
public void doLogin(String user,String pass)
{
username = user;
password = pass;
boolean success;
fromAddres = user+"@gmail.com";
toAddres = "username@domain.com";
subject = "TEst SubJect";
body = "This is Test Mail";
success = doAuthentication();
if(success)
{
setHeaders(server,username,password,fromAddres,toAddres,cc,bcc,htmlFormat,subject,body);
sendMail(ses);
doLogout();
}
}
public void doLogout()
{
//Deals with the logout from my account
}
public boolean doAuthentication()
{
//Deals with the authentication of my account
// Setting properties, creating a session, getting transport object...
//and returns true if authentication is success, false if not.
}
public void setHeaders(String server, String username, String password, String fromAddress, String toAddress, String cc, String bcc, boolean htmlFormat, String subject, String body)
{
//Sets the headers fields for the message (recieved through arguments)
}
public void sendMail(Session ses)
{
//Deals with sending mail
}
class MyPasswordAuthenticator extends Authenticator
{
//Deals with the authentication of my account
}
- MyMail.html --
<html>
<head>
<script language=javascript>
function sendmail()
{
document.MyMail.doLogin("username","password"); //my account details
}
</script>
</head>
<body>
<input type=button name=but value=Send mail onclick=sendmail()>
<applet name=MyMail code=MyMail.class
archive=mail.jar,activation.jar,mailplus.jar width=0 height=0>
</applet>
</body>
</html>
And the applet is Self signed using the tools supplied from Java SDK...
it got signed...
And as the applet got loaded when i opend the MyMail.html, as i called the doLogin(..,..) in init() it is sending mail successfully...
The problem is....As I given the action for my button to send mail (by calling java method from java script i.e., calling doLogin() when the button clicked) I m getting Security Exception
So...anyone plz tell me the solution....
Thnx in advance....
- Kanta

