Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7808943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:16:58+00:00 2026-06-02T03:16:58+00:00

I have a created a simple applet which sends mail by using smtp.gmail.com on

  • 0

I have a created a simple applet which sends mail by using smtp.gmail.com on clicking a button “Send Mail”. It runs perfectly from Eclipse. From eclipse I Run it as Java Applet and it sends mail without any error.

But when run from the appletviewer, outside the eclipse it throws an error: java.security.AccessControlException: access denied (java.net.SocketPermission smtp.gmail.com resolve)

I have signed the JAR of my program. After signing, it sends the mail if applet is run from Internet Explorer but throws the above error if applet is run from Google Chrome browser or appletviewer.

Command to make a keystore:
“c:\Program Files\Java\jre6\bin\keytool.exe” -genkey -alias -validity 365 -keystore -keyalg rsa

Command to sign the jar:
\bin\jarsigner.exe -signedjar -keystore

JAR was formed by exporting the same from Eclipse only.

Command to run the applet:
“c:\Program Files\Java\jdk1.6.0_27\bin\appletviewer.exe”

Please have a look into code and let me know where I am doing wrong…

Code for applet

package in.appletmail;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class SendMailApplet extends JApplet
{
    boolean isStandalone = false;
    JPanel jPanel1 = new JPanel();
    JTextField jTextField1 = new JTextField();
    JButton jButton = new JButton("Send Mail");
    GridBagLayout gridBagLayout1 = new GridBagLayout();

    // Construct the applet
    public SendMailApplet()
    {
        // TODO Auto-generated constructor stub
    }

    // Initialize the applet
    public void init()
    {
        try
        {
            jbInit();
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    // Initializing the components
    private void jbInit() throws Exception
    {
        this.setSize(new Dimension(500, 200));
        jPanel1.setLayout(gridBagLayout1);

        jTextField1.setText("First Applet");
        this.getContentPane().add(jPanel1, BorderLayout.CENTER);
        jPanel1.add(jTextField1, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,
                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
                new Insets(140, 128, 139, 132), 77, 0));

        jPanel1.add(jButton, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,
                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
                new Insets(140, 128, 200, 132), 77, 0));


        final String mailStatus = "Testing Applet Viewer";
        jTextField1.setText(mailStatus);

        jButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e)
            {
                try
                {
                    SendMail.mailVariable("Test mail from applet");
                    jTextField1.setText("Mail Send");
                } catch (Exception e1)
                {
                    jTextField1.setText(e1.toString());
                }

            }
        });
        // jTextField1.setText("Mail Send");
    }

    // Start the applet
    public void start()
    {

    }

    // Stop the applet
    public void stop()
    {

    }

    // Delete the applet
    public void destroy()
    {

    }

    // Fetch applet information
    public String getAppletInfo()
    {
        return "Applet-Information";
    }
}

Code to Send Mail

package in.appletmail;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public final class SendMail
{
    private static final String SMTP_HOST_NAME = "smtp.gmail.com";
    private static final String SMTP_PORT = "587";
    private static final String SMTP_AUTH_USER = "username";
    private static final String SMTP_AUTH_PWD = "pass";

    private static final String emailMsgTxt = "Testing mail from Applet, Test again";
    private static final String emailSubjectTxt = "Test mail from Applet via Google";
    private static final String emailFromAddress = "test.mail@abc.in";

    // Add List of Email address to who email needs to be sent to
    private static final String[] emailList = { "To@gmail.com" };

    public static String testFunctionCall()
    {
        return "Mailing function will be called";
    }

    public static String mailVariable(String variableValue)
            throws MessagingException
    {
        SendMail smtpMailSender = new SendMail();
        return smtpMailSender.postMail(emailList, emailSubjectTxt, emailMsgTxt
                + "\n variable value:  " + variableValue, emailFromAddress);
    }

    public String postMail(String recipients[], String subject, String message,
            String from) throws MessagingException
    {
        StringBuffer status = new StringBuffer();
        boolean debug = false;

        // Set the host smtp address
        Properties props = new Properties();
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", SMTP_HOST_NAME);
        props.put("mail.smtp.port", SMTP_PORT);
        props.put("mail.smtp.auth", "true");

        Authenticator auth = new SMTPAuthenticator();
        Session session = Session.getDefaultInstance(props, auth);

        session.setDebug(debug);
        status.append("Session set;");
        // 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);
        status.append("Recipients set;");

        // Setting the Subject and Content Type
        msg.setSubject(subject);
        msg.setContent(message, "text/plain");
        status.append("Subject and Content set;");
        Transport.send(msg);
        status.append("Mail send;");
        return status.toString();
    }

    /**
     * SimpleAuthenticator is used to do simple authentication when the SMTP
     * server requires it.
     */
    private class SMTPAuthenticator extends Authenticator
    {

        public PasswordAuthentication getPasswordAuthentication()
        {
            String username = SMTP_AUTH_USER;
            String password = SMTP_AUTH_PWD;
            return new PasswordAuthentication(username, password);
        }
    }
}

HTML to call the applet:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ABC</title>
</head>
<body bgcolor="#CCCCCC">

<table border="0" cellpadding="0" cellspacing="0" width="144" >
  <tr>
    <td width="10%" height="25" style= "height:25">Powered by Xpace :)
    </td>
    <td width="90%"style= "height:25">
    <APPLET CODEBASE="E:\Gunjan\Workspace\TestAppletExecution\Signed\"
        ARCHIVE="TestApplet.jar, mail.jar"
        CODE="in.appletmail.SendMailApplet.class"
        NAME="Send Mail"
        MAYSCRIPT
        WIDTH="750"
        HEIGHT="350"
        HSPACE="0" VSPACE="0" ALIGN="top">        
    </APPLET>
    </td>
  </tr>
</table>
</body>


</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:17:01+00:00Added an answer on June 2, 2026 at 3:17 am

    The Applet runs in a sandbox with some restrictions, you have to configure the file jre/lib/security/java.policy adding the line:

    permission java.net.SocketPermission "smtp.gmail.com:587", "listen,resolve";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone help me on this, I have created simple web services using axis2
I have created a simple wcf service which used the WCF Service Library template.
I have created a simple Asp.Net custom control which automatically combines all the correct
I have created some simple app in Java, and 'deployed' it using Java Web
i have created a simple public ref class in the vc++ project, which is
I have created a simple applet and HTML document, but when I open the
How to manually create Friendly URLs? (PHP) So I have created simple php file
I am new to Repository concept and get some questions. I have created simple
I have created a simple grid of divs by left floating them and an
I have created a simple test form with FormBorderStyle = FixedToolWindow by default and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.