Results 1 to 2 of 2
  1. #1
    mabirc is offline Member
    Join Date
    Feb 2016
    Posts
    1
    Rep Power
    0

    Question HELP: Mailclient

    Hey guys,

    i have a problem in school with creating a mailclient with java.

    We need a solution, please help us!

    This should be working:

    [SPOILER="Mailclient GUI"][ATTACH=full]8618[/ATTACH][/SPOILER]

    This is our attempt, but there are too much errors:

    [SPOILER="MailClient"]
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;

    /**
    *
    * Beschreibung
    *
    * @version 1.0 vom 01.02.2016
    * @author
    */

    public class emailsenden extends JFrame {
    // Anfang Attribute
    private TextField textField5 = new TextField();
    private TextField textField6 = new TextField();
    private Label label8 = new Label();
    private Label label9 = new Label();
    private Label label10 = new Label();
    private Label label11 = new Label();
    private Button button3 = new Button();
    private TextField textField1 = new TextField();
    private Label label2 = new Label();
    private TextField textField2 = new TextField();
    private Label label3 = new Label();
    private TextField textField3 = new TextField();
    private Label label4 = new Label();
    private Label label5 = new Label();
    private NumberField numberField2 = new NumberField();
    private Button button2 = new Button();
    private JSeparator jSeparator1 = new JSeparator();
    private TextField textField4 = new TextField();
    // Ende Attribute
    public emailsenden(String title) {
    // Frame-Initialisierung
    super(title);
    setDefaultCloseOperation(WindowConstants.DISPOSE_O N_CLOSE);
    int frameWidth = 580;
    int frameHeight = 647;
    setSize(frameWidth, frameHeight);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (d.width - getSize().width) / 2;
    int y = (d.height - getSize().height) / 2;
    setLocation(x, y);
    setResizable(false);
    Container cp = getContentPane();
    cp.setLayout(null);
    // Anfang Komponenten

    cp.setBackground(new Color(0xB8CFE5));
    textField5.setBounds(150, 200, 390, 20);
    cp.add(textField5);
    textField6.setBounds(150, 240, 390, 20);
    cp.add(textField6);
    label8.setBounds(30, 200, 110, 21);
    label8.setText("Empfaenger");
    label8.setBackground(new Color(0xA3B8CC));
    label8.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
    label8.setForeground(Color.WHITE);
    cp.add(label8);
    label9.setBounds(30, 240, 110, 21);
    label9.setText("Betreff");
    label9.setBackground(new Color(0xA3B8CC));
    label9.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
    label9.setForeground(Color.WHITE);
    cp.add(label9);
    label10.setBounds(30, 280, 110, 21);
    label10.setText("Mailinhalt:");
    label10.setBackground(new Color(0xA3B8CC));
    label10.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
    label10.setForeground(Color.WHITE);
    cp.add(label10);
    label11.setBounds(213, 24, 167, 29);
    label11.setText("Neue E-Mail schreiben");
    label11.setBackground(new Color(0xA3B8CC));
    label11.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 16));
    label11.setForeground(Color.WHITE);
    cp.add(label11);
    button3.setBounds(465, 561, 75, 25);
    button3.setLabel("Senden");
    button3.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    button3_ActionPerformed(evt);
    }
    });
    button3.setBackground(new Color(0xA3B8CC));
    button3.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
    button3.setForeground(Color.WHITE);
    cp.add(button3);
    textField1.setBounds(152, 280, 390, 260);
    cp.add(textField1);
    label2.setBounds(24, 72, 110, 21);
    label2.setText("Benutzername");
    label2.setBackground(new Color(0xA3B8CC));
    label2.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
    label2.setForeground(Color.WHITE);
    cp.add(label2);
    textField2.setBounds(152, 72, 150, 20);
    textField2.setText("LeonW@gsg.de");
    cp.add(textField2);
    label3.setBounds(24, 104, 110, 21);
    label3.setText("Passwort");
    label3.setBackground(new Color(0xA3B8CC));
    label3.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
    label3.setForeground(Color.WHITE);
    cp.add(label3);
    textField3.setBounds(152, 104, 150, 20);
    textField3.setText("geheim");
    cp.add(textField3);
    label4.setBounds(328, 72, 110, 21);
    label4.setText("Server");
    label4.setBackground(new Color(0xA3B8CC));
    label4.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
    label4.setForeground(Color.WHITE);
    cp.add(label4);
    label5.setBounds(328, 104, 110, 21);
    label5.setText("Port");
    label5.setBackground(new Color(0xA3B8CC));
    label5.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
    label5.setForeground(Color.WHITE);
    cp.add(label5);
    numberField2.setBounds(456, 104, 83, 20);
    numberField2.setText("2110");
    cp.add(numberField2);
    button2.setBounds(464, 144, 75, 25);
    button2.setLabel("Einloggen");
    button2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    button2_ActionPerformed(evt);
    }
    });
    button2.setBackground(new Color(0xA3B8CC));
    button2.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
    button2.setForeground(Color.WHITE);
    cp.add(button2);
    jSeparator1.setBounds(13, 184, 532, 2);
    cp.add(jSeparator1);
    textField4.setBounds(456, 72, 86, 20);
    textField4.setText("172.16.3.145");
    cp.add(textField4);
    // Ende Komponenten

    setVisible(true);
    } // end of public emailsenden
    // Anfang Methoden
    public static void main(String[] args) {
    new emailsenden("emailsenden");
    } // end of main
    public void button2_login(ActionEvent evt) {
    mail.smtp.user=getText.textField2;
    mail.smtp.password=getText.textField3;
    mail.smtp.host=getText.textField4;
    mail.smtp.port=getText.numberField2;

    Transport tr = session.getTransport();
    tr.connect(null, password);
    tr.sendMessage(message, message.getRecipients());
    } // end of button2_ActionPerformed
    public void button3_mailsenden(String [] args)
    {
    String to = getText.textField5;
    String from = getText.textField2;
    String host = getText.numberField2;
    Properties properties = System.getProperties();
    properties.setProperty(getText.textField4, host);
    Session session = Session.getDefaultInstance(properties);

    try{
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    Transport.send(message);
    System.out.println("Nachricht erfolgreich verschickt...");
    }catch (MessagingException mex) {
    mex.printStackTrace();
    }
    }// end of button2_ActionPerformed
    // Ende Methoden
    } // end of class emailsenden

    [/SPOILER]

    You don't have to be guided by our attempt and can write an own new programm.

    Thank you!

    Cheers
    Mabirc

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: HELP: Mailclient

    I've formatted your code so I can point you to the line numbers. Below the code are my comments.

    Java Code:
    package forums;
    
    import javax.mail.*;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Properties;
    
    /**
     * Beschreibung
     *
     * @author
     * @version 1.0 vom 01.02.2016
     */
    
    public class emailsenden extends JFrame {
        // Anfang Attribute
        private TextField textField5 = new TextField();
        private TextField textField6 = new TextField();
        private Label label8 = new Label();
        private Label label9 = new Label();
        private Label label10 = new Label();
        private Label label11 = new Label();
        private Button button3 = new Button();
        private TextField textField1 = new TextField();
        private Label label2 = new Label();
        private TextField textField2 = new TextField();
        private Label label3 = new Label();
        private TextField textField3 = new TextField();
        private Label label4 = new Label();
        private Label label5 = new Label();
        private NumberField numberField2 = new NumberField();
        private Button button2 = new Button();
        private JSeparator jSeparator1 = new JSeparator();
        private TextField textField4 = new TextField();
    
        // Ende Attribute
        public emailsenden(String title) {
    // Frame-Initialisierung
            super(title);
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            int frameWidth = 580;
            int frameHeight = 647;
            setSize(frameWidth, frameHeight);
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            int x = (d.width - getSize().width) / 2;
            int y = (d.height - getSize().height) / 2;
            setLocation(x, y);
            setResizable(false);
            Container cp = getContentPane();
            cp.setLayout(null);
    // Anfang Komponenten
    
            cp.setBackground(new Color(0xB8CFE5));
            textField5.setBounds(150, 200, 390, 20);
            cp.add(textField5);
            textField6.setBounds(150, 240, 390, 20);
            cp.add(textField6);
            label8.setBounds(30, 200, 110, 21);
            label8.setText("Empfaenger");
            label8.setBackground(new Color(0xA3B8CC));
            label8.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
            label8.setForeground(Color.WHITE);
            cp.add(label8);
            label9.setBounds(30, 240, 110, 21);
            label9.setText("Betreff");
            label9.setBackground(new Color(0xA3B8CC));
            label9.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
            label9.setForeground(Color.WHITE);
            cp.add(label9);
            label10.setBounds(30, 280, 110, 21);
            label10.setText("Mailinhalt:");
            label10.setBackground(new Color(0xA3B8CC));
            label10.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
            label10.setForeground(Color.WHITE);
            cp.add(label10);
            label11.setBounds(213, 24, 167, 29);
            label11.setText("Neue E-Mail schreiben");
            label11.setBackground(new Color(0xA3B8CC));
            label11.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 16));
            label11.setForeground(Color.WHITE);
            cp.add(label11);
            button3.setBounds(465, 561, 75, 25);
            button3.setLabel("Senden");
            button3.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    button3_ActionPerformed(evt);
                }
            });
            button3.setBackground(new Color(0xA3B8CC));
            button3.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
            button3.setForeground(Color.WHITE);
            cp.add(button3);
            textField1.setBounds(152, 280, 390, 260);
            cp.add(textField1);
            label2.setBounds(24, 72, 110, 21);
            label2.setText("Benutzername");
            label2.setBackground(new Color(0xA3B8CC));
            label2.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
            label2.setForeground(Color.WHITE);
            cp.add(label2);
            textField2.setBounds(152, 72, 150, 20);
            textField2.setText("LeonW@gsg.de");
            cp.add(textField2);
            label3.setBounds(24, 104, 110, 21);
            label3.setText("Passwort");
            label3.setBackground(new Color(0xA3B8CC));
            label3.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
            label3.setForeground(Color.WHITE);
            cp.add(label3);
            textField3.setBounds(152, 104, 150, 20);
            textField3.setText("geheim");
            cp.add(textField3);
            label4.setBounds(328, 72, 110, 21);
            label4.setText("Server");
            label4.setBackground(new Color(0xA3B8CC));
            label4.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
            label4.setForeground(Color.WHITE);
            cp.add(label4);
            label5.setBounds(328, 104, 110, 21);
            label5.setText("Port");
            label5.setBackground(new Color(0xA3B8CC));
            label5.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
            label5.setForeground(Color.WHITE);
            cp.add(label5);
            numberField2.setBounds(456, 104, 83, 20);
            numberField2.setText("2110");
            cp.add(numberField2);
            button2.setBounds(464, 144, 75, 25);
            button2.setLabel("Einloggen");
            button2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    button2_ActionPerformed(evt);
                }
            });
            button2.setBackground(new Color(0xA3B8CC));
            button2.setFont(new Font("@Kozuka Gothic Pro B", Font.BOLD, 12));
            button2.setForeground(Color.WHITE);
            cp.add(button2);
            jSeparator1.setBounds(13, 184, 532, 2);
            cp.add(jSeparator1);
            textField4.setBounds(456, 72, 86, 20);
            textField4.setText("172.16.3.145");
            cp.add(textField4);
    // Ende Komponenten
    
            setVisible(true);
        } // end of public emailsenden
    
        // Anfang Methoden
        public static void main(String[] args) {
            new emailsenden("emailsenden");
        } // end of main
    
        public void button2_login(ActionEvent evt) {
            mail.smtp.user = getText.textField2;
            mail.smtp.password = getText.textField3;
            mail.smtp.host = getText.textField4;
            mail.smtp.port = getText.numberField2;
    
            Transport tr = session.getTransport();
            tr.connect(null, password);
            tr.sendMessage(message, message.getRecipients());
        } // end of button2_ActionPerformed
    
        public void button3_mailsenden(String[] args) {
            String to = getText.textField5;
            String from = getText.textField2;
            String host = getText.numberField2;
            Properties properties = System.getProperties();
            properties.setProperty(getText.textField4, host);
            Session session = Session.getDefaultInstance(properties);
    
            try {
                MimeMessage message = new MimeMessage(session);
                message.setFrom(new InternetAddress(from));
                message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
                Transport.send(message);
                System.out.println("Nachricht erfolgreich verschickt...");
            }
            catch (MessagingException mex) {
                mex.printStackTrace();
            }
        }// end of button2_ActionPerformed
    // Ende Methoden
    } // end of class emailsenden


    - You are missing imports for javax.mail.*
    - Line 35: NumberField is a unknown class. There is no import for it, and Java doesn't have one.
    - Line 90: Method button3_ActionPerformed() does not exist. I am assuming this should be button3_mailsenden()
    - Line 129+130: The methods are marked as non existent because Java does not know the NumberField class
    - Line 136: Method button2_ActionPerformed() does not exist. I am assuming this should be buttoin2_login()
    - Line 158: The parameter evt does nothing. Delete it.
    - Line 159 and 170: It looks like you're trying to create mail properties. It should be done like this:
    Java Code:
    Properties props = new Properties();
    props.put("mail.smtp.user", textField2.getText());
    props.put("mail.smtp.password", textField3.getText());
    etc...
    - Line 169: The parameter args does nothing. Delete it.



    You don't have to be guided by our attempt and can write an own new programm.
    Nice try, but this is not a CodeFactory™ or a HomeWorkAutomationTool™. Next time, also post the errors you get during compiling and/or running.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •