my problem comes up with the code is creating an envelope it keeps saying that envelope can not be resolved to a variable any idea on how to fix this?

import java.awt.*;
import java.awt.event.*;

/* $Id:,v 1.7 1999/07/22 12:07:30 kangasha Exp $ */

 * A simple mail client with a GUI for sending mail.

public class MailClient extends Frame {/* The stuff for the GUI. */
    private Button btSend = new Button("Send");
    private Button btClear = new Button("Clear");
    private Button btQuit = new Button("Quit");
    private Label serverLabel = new Label("Local mailserver:");
    private TextField serverField = new TextField("", 40);
    private Label fromLabel = new Label("From:");
    private TextField fromField = new TextField("", 40);
    private Label toLabel = new Label("To:"); 
    private TextField toField = new TextField("", 40);
    private Label subjectLabel = new Label("Subject:");
    private TextField subjectField = new TextField("", 40);
    private Label messageLabel = new Label("Message:");
    private TextArea messageText = new TextArea(10, 40);

     * Create a new MailClient window with fields for entering all
	public MailClient() {

    static public void main(String argv[]) {

    /* Handler for the Send-button. */
    class SendListener implements ActionListener {
        public void actionPerformed(ActionEvent event) {
            System.out.println("Sending mail");
            /* Check that we have the local mailserver */
            if ((serverField.getText()).equals("")) {
                System.out.println("Need name of local mailserver!");

            /* Check that we have the sender and recipient. */
            if((fromField.getText()).equals("")) {
                System.out.println("Need sender!");
            if((toField.getText()).equals("")) {
                System.out.println("Need recipient!");

            /* Create the message */
            Message mailMessage = new Message(fromField.getText(), 

            /* Check that the message is valid, i.e., sender and
               recipient addresses look ok. */
            if(!mailMessage.isValid()) {

            /* Create the envelope, open the connection and try to send
               the message. */
            try {
                Envelope envelope = new Envelope(mailMessage, 
            } catch (UnknownHostException e) {
                /* If there is an error, do not go further */
            try {
                SMTPConnection connection = new SMTPConnection(envelope);
            } catch (IOException error) {
                System.out.println("Sending failed: " + error);
            System.out.println("Mail sent succesfully!");

    /* Clear the fields on the GUI. */
    class ClearListener implements ActionListener {

    /* Quit. */
    class QuitListener implements ActionListener {


You declared envelope by itself in a try-catch block and then tried to use it in a different block. It went out of scope when the first block ended, so essentially the second try-catch block can't "see" that variable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.