创建创建和通过电子邮件发送文件的Java程序

时间:2016-12-05 15:06:48

标签: java email netbeans

我创建了一个应用程序,用于收集表单数据并将其保存到文本文件中。现在,我接收该信息的唯一方法是让用户手动通过电子邮件发送文件。我希望应用程序在用户按下提交时自动发送电子邮件,以使该过程更加用户友好。我该怎么做呢?这是我的代码。我在网上发现了一些东西,但一切似乎已经过时,不再有效。提前谢谢!

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    JOptionPane.showMessageDialog(frame, "Thank you for joining BPA! A file has been created on your desktop. Please send the file to bpasignup@gmail.com to complete your registration.");
    String content = "," + FName.getText() + "," +
                     MName.getText() + "," + 
                     LName.getText() + "," + 
                     Email.getText() + "," + 
                     Phone.getText() + "," + 
                     SAddress.getText() + "," + 
                     City.getText() + "," +  
                     State.getSelectedItem() + "," +
                     ZIP.getText() + "," + 
                     Grade.getSelectedItem() + "," +
                     Shop.getSelectedItem() + "," +
                     HRoom.getText() + "," +
                     PName.getText() + "," +
                     PEmail.getText() + "," 
                     ;





try {

            File file = new File("c:/users/User/desktop/BPAsignup.txt");

            // if file doesnt exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            }

            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);    //step2: write it
            bw.close();

            System.out.println("Done");

        } catch (IOException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(frame, "Unable to create file. Please contact your BPA director directly to resolve this issue.");

0 个答案:

没有答案