Advertisement
Guest User

GMAILCLIENT

a guest
Feb 4th, 2019
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.99 KB | None | 0 0
  1. import java.util.Properties;
  2. import javax.mail.Message;
  3. import javax.mail.MessagingException;
  4. import javax.mail.PasswordAuthentication;
  5. import javax.mail.Session;
  6. import javax.mail.Transport;
  7. import javax.mail.internet.InternetAddress;
  8. import javax.mail.internet.MimeMessage;
  9. import javax.mail.internet.MimeBodyPart;
  10. import javax.mail.Multipart;
  11. import javax.activation.*;
  12. import javax.mail.internet.MimeMultipart;
  13.  
  14. import java.io.*;
  15.  
  16. import javax.swing.*;
  17. import javax.swing.JOptionPane;
  18.  
  19. import org.openqa.selenium.*;
  20. import org.openqa.selenium.MutableCapabilities;
  21. import org.openqa.selenium.By;
  22. import org.openqa.selenium.WebElement;
  23. import org.openqa.selenium.WebDriver;
  24. import org.openqa.selenium.firefox.*;
  25. import org.openqa.selenium.firefox.FirefoxProfile;
  26. import org.openqa.selenium.firefox.FirefoxDriver;
  27. import org.openqa.selenium.support.ui.WebDriverWait;
  28.  
  29. import org.jsoup.*;
  30. import org.jsoup.Jsoup;
  31. import org.jsoup.helper.Validate;
  32. import org.jsoup.nodes.Document;
  33. import org.jsoup.nodes.Element;
  34. import org.jsoup.select.Elements;
  35.  
  36. import java.util.concurrent.TimeUnit;
  37.  
  38. WebDriver driver = new FirefoxDriver();
  39.  
  40. public String ALPHANUMERIC = "";
  41. String TargetUrl = JOptionPane.showInputDialog( "Enter the url to scrub" );
  42. //"cc";
  43.  
  44. String UNIV_LINE = "";
  45.  
  46. void setup()
  47.   {
  48.     try
  49.       {
  50.         driver.manage().window().setSize(new Dimension(20, 20));
  51.         Thread.sleep( 500 );
  52.       }
  53.     catch( Exception e )
  54.       {
  55.        
  56.       }
  57.      
  58.     float ms = millis();
  59.    
  60.     //StartScruber();
  61.     CheckCode();
  62.     println( millis() - ms );
  63.     // end of line is \r\n
  64.     //SendMessage( "smtp.gmail.com", "freepromsoftware2@gmail.com", "nmsgkylrltxdahzl", "freepromsoftware@gmail.com", "CODE", "blip blop", "captcha/image2181.gif", "captcha/image2180.gif" );
  65.   }
  66.  
  67. void draw()
  68.   {
  69.     background( 0 );
  70.     //println( ALPHANUMERIC );
  71.   }
  72.  
  73. void CheckCode()
  74.   {
  75.     StartScruber();
  76.    
  77.     if( ALPHANUMERIC != null )
  78.       {
  79.         try
  80.           {
  81.             BufferedReader br = new BufferedReader( new FileReader( new File( "EMAIL.csv" ) ) );
  82.             String line = br.readLine();
  83.            
  84.             int i = 0;
  85.            
  86.             while( line != null )
  87.               {
  88.                 if( i >= 2 )
  89.                   {
  90.                     UNIV_LINE = line;
  91.                     println( ALPHANUMERIC );
  92.                     thread( "SendMessage" );
  93.                     Thread.sleep( 2 );
  94.                   }
  95.                  
  96.                 i++;
  97.                 line = br.readLine();
  98.               }
  99.             br.close();
  100.           }
  101.         catch( Exception e )
  102.           {
  103.             e.printStackTrace();
  104.           }
  105.          
  106.       }
  107.   }
  108.  
  109. void StartScruber()
  110.   {
  111.     GetCode();
  112.   }
  113.  
  114. void GetCode()
  115.   {
  116.     try
  117.       {
  118.         driver.get( TargetUrl );
  119.        
  120.         while( ALPHANUMERIC.length() < 2 )
  121.           {
  122.             try
  123.               {
  124.                 Thread.sleep( 20 );
  125.                 Document doc = Jsoup.parse( driver.getPageSource() );
  126.                 String CODE = doc.title().replace( "The alphanumeric code valid for short-term visa for citizens of Bangladesh and Nepal is as follows: ", "" ).split( "\\(" )[ 0 ];
  127.                 ALPHANUMERIC = ( CODE );
  128.                
  129.                 if( !doc.title().contains( "The alphanumeric code valid for short-term visa for citizens of Bangladesh and Nepal is as follows: " ) )
  130.                   {
  131.                     ALPHANUMERIC = "";
  132.                   }
  133.               }
  134.             catch( Exception e )
  135.               {
  136.               }
  137.           }
  138.       }
  139.     catch( Exception e )
  140.       {
  141.       }
  142.   }
  143.  
  144. void SendMessage()
  145.   {
  146.    
  147.     String line = "" + UNIV_LINE;
  148.    
  149.     String HOST = line.split( "," )[ 0 ];
  150.     final String USER = line.split( "," )[ 1 ];
  151.     final String PASS = line.split( "," )[ 2 ];
  152.     String RECPT = line.split( "," )[ 3 ];
  153.     String FIRST = line.split( "," )[ 4 ];
  154.     String LAST = line.split( "," )[ 5 ];
  155.     String DOB = line.split( "," )[ 6 ];
  156.     String PASSPORT = line.split( "," )[ 7 ];
  157.     String PURPOSE = line.split( "," )[ 8 ];
  158.     String PHONE = line.split( "," )[ 9 ];
  159.     String EMAIL = line.split( "," )[ 10 ];
  160.     String FILE1 = line.split( "," )[ 11 ];
  161.     String FILE2 = line.split( "," )[ 12 ];
  162.    
  163.     String MSG = "FIRST AND SUR NAME: " + FIRST + " " + LAST + "\r\n";
  164.     MSG += "DATE OF BIRTH: " + DOB + "\r\n";
  165.     MSG += "PASSPORT NUMBER: " + PASSPORT + "\r\n";
  166.     MSG += "PURPOSE OF TRAVEL: " + PURPOSE + "\r\n";
  167.     MSG += "PHONE: " + PHONE + "\r\n";
  168.     MSG += "EMAIL: " + EMAIL + "\r\n";
  169.    
  170.     println( MSG );
  171.    
  172.     try
  173.       {
  174.         Properties props = new Properties();
  175.         props.put("mail.smtp.host", HOST );
  176.         props.put("mail.smtp.socketFactory.port", "465" );
  177.         props.put("mail.smtp.socketFactory.class",
  178.             "javax.net.ssl.SSLSocketFactory" );
  179.         props.put("mail.smtp.auth", "true" );
  180.         props.put("mail.smtp.port", "587" );
  181.    
  182.         Session session = Session.getDefaultInstance(props,
  183.           new javax.mail.Authenticator() {
  184.             protected PasswordAuthentication getPasswordAuthentication() {
  185.               return new PasswordAuthentication( USER, PASS );
  186.             }
  187.           });
  188.    
  189.         try {
  190.    
  191.           Message message = new MimeMessage(session);
  192.           message.setFrom( new InternetAddress( EMAIL ) );
  193.           message.setRecipients( Message.RecipientType.TO,
  194.               InternetAddress.parse( RECPT ) );
  195.           message.setSubject( ALPHANUMERIC );
  196.           message.setText( "Dear Mail Crawler," +
  197.               "\n\n No spam to my email, please!" );
  198.              
  199.           MimeBodyPart messageBodyPart = new MimeBodyPart();
  200.  
  201.           Multipart multipart = new MimeMultipart();
  202.  
  203.           messageBodyPart = new MimeBodyPart();
  204.           String file = FILE1;
  205.           String fileName = FILE1;
  206.           DataSource source = new FileDataSource(file);
  207.           messageBodyPart.setDataHandler(new DataHandler(source));
  208.           messageBodyPart.setFileName(fileName);
  209.           multipart.addBodyPart(messageBodyPart);
  210.          
  211.           MimeBodyPart messageBodyPart2 = new MimeBodyPart();
  212.  
  213.           String file2 = FILE2;
  214.           String fileName2 = FILE2;
  215.           DataSource source2 = new FileDataSource(file2);
  216.           messageBodyPart2.setDataHandler(new DataHandler(source2));
  217.           messageBodyPart2.setFileName(fileName2);
  218.           multipart.addBodyPart(messageBodyPart2);
  219.          
  220.           MimeBodyPart textPart = new MimeBodyPart();
  221.           textPart.setText( MSG, "utf-8" );
  222.           multipart.addBodyPart(textPart);
  223.          
  224.           message.setContent(multipart);
  225.          
  226.           Transport.send(message);
  227.    
  228.           System.out.println("Done");
  229.    
  230.         } catch (MessagingException e) {
  231.           throw new RuntimeException(e);
  232.         }
  233.       }
  234.     catch( Exception e )
  235.       {
  236.         e.printStackTrace();
  237.       }
  238.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement