Guest User

Untitled

a guest
Feb 7th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 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.jsoup.*;
  20. import org.jsoup.Jsoup;
  21. import org.jsoup.helper.Validate;
  22. import org.jsoup.nodes.Document;
  23. import org.jsoup.nodes.Element;
  24. import org.jsoup.select.Elements;
  25.  
  26. import java.util.concurrent.TimeUnit;
  27.  
  28. public String ALPHANUMERIC = "AM9QBUSV";
  29.  
  30. //"cc";
  31.  
  32. String UNIV_LINE = "";
  33.  
  34. void setup()
  35. {
  36.  
  37. float ms = millis();
  38.  
  39. //StartScruber();
  40. CheckCode();
  41. println( millis() - ms );
  42. }
  43.  
  44. void draw()
  45. {
  46. background( 0 );
  47. //println( ALPHANUMERIC );
  48. }
  49.  
  50. void CheckCode()
  51. {
  52.  
  53. try
  54. {
  55. BufferedReader br = new BufferedReader( new FileReader( new File( "EMAIL.csv" ) ) );
  56. String line = br.readLine();
  57.  
  58. int i = 0;
  59.  
  60. while( line != null )
  61. {
  62. if( i >= 2 )
  63. {
  64. UNIV_LINE = line;
  65. println( ALPHANUMERIC );
  66. thread( "SendMessage" );
  67. Thread.sleep( 2 );
  68. }
  69.  
  70. i++;
  71. line = br.readLine();
  72. }
  73. br.close();
  74. }
  75. catch( Exception e )
  76. {
  77. e.printStackTrace();
  78. }
  79.  
  80.  
  81. }
  82.  
  83. void SendMessage()
  84. {
  85.  
  86. String line = "" + UNIV_LINE;
  87.  
  88. String HOST = line.split( "," )[ 0 ];
  89. final String USER = line.split( "," )[ 1 ];
  90. final String PASS = line.split( "," )[ 2 ];
  91. String RECPT = line.split( "," )[ 3 ];
  92. String FIRST = line.split( "," )[ 4 ];
  93. String LAST = line.split( "," )[ 5 ];
  94. String DOB = line.split( "," )[ 6 ];
  95. String PASSPORT = line.split( "," )[ 7 ];
  96. String PURPOSE = line.split( "," )[ 8 ];
  97. String PHONE = line.split( "," )[ 9 ];
  98. String EMAIL = line.split( "," )[ 10 ];
  99. String FILE1 = line.split( "," )[ 11 ];
  100. String FILE2 = line.split( "," )[ 12 ];
  101.  
  102. String MSG = "\r\n" + "Dear Sir/Madam" + "\r\n";
  103. MSG += "\r\n" + "Please check attached file below: " + " \r\n";
  104. MSG += "\r\n" + "FIRST AND SUR NAME: " + FIRST + " " + LAST + "\r\n";
  105. MSG += "DATE OF BIRTH: " + DOB + "\r\n";
  106. MSG += "PASSPORT NUMBER: " + PASSPORT + "\r\n";
  107. MSG += "PURPOSE OF TRAVEL: " + PURPOSE + "\r\n";
  108. MSG += "PHONE: " + PHONE + "\r\n";
  109. MSG += "EMAIL: " + EMAIL + "\r\n";
  110. MSG += "\r\n" + "Thanks";
  111. MSG += "\r\n" + FIRST + " " + LAST + "\r\n \r\n \r\n";
  112.  
  113. println( MSG );
  114.  
  115. try
  116. {
  117. Properties props = new Properties();
  118. props.put("mail.smtp.host", HOST );
  119. props.put("mail.smtp.socketFactory.port", "465" );
  120. props.put("mail.smtp.socketFactory.class",
  121. "javax.net.ssl.SSLSocketFactory" );
  122. props.put("mail.smtp.auth", "true" );
  123. props.put("mail.smtp.port", "587" );
  124.  
  125. Session session = Session.getDefaultInstance(props,
  126. new javax.mail.Authenticator() {
  127. protected PasswordAuthentication getPasswordAuthentication() {
  128. return new PasswordAuthentication( USER, PASS );
  129. }
  130. });
  131.  
  132. try {
  133.  
  134. Message message = new MimeMessage(session);
  135. message.setFrom( new InternetAddress( EMAIL ) );
  136. message.setRecipients( Message.RecipientType.TO,
  137. InternetAddress.parse( RECPT ) );
  138. message.setSubject( ALPHANUMERIC );
  139. message.setText( "" );
  140.  
  141. MimeBodyPart messageBodyPart = new MimeBodyPart();
  142.  
  143. Multipart multipart = new MimeMultipart();
  144.  
  145. MimeBodyPart textPart = new MimeBodyPart();
  146. textPart.setText( MSG, "utf-8" );
  147. multipart.addBodyPart(textPart);
  148.  
  149. message.setContent(multipart);
  150.  
  151. messageBodyPart = new MimeBodyPart();
  152. String file = FILE1;
  153. String fileName = FILE1;
  154. DataSource source = new FileDataSource(file);
  155. messageBodyPart.setDataHandler(new DataHandler(source));
  156. messageBodyPart.setFileName(fileName);
  157. multipart.addBodyPart(messageBodyPart);
  158.  
  159. MimeBodyPart messageBodyPart2 = new MimeBodyPart();
  160.  
  161. String file2 = FILE2;
  162. String fileName2 = FILE2;
  163. DataSource source2 = new FileDataSource(file2);
  164. messageBodyPart2.setDataHandler(new DataHandler(source2));
  165. messageBodyPart2.setFileName(fileName2);
  166. multipart.addBodyPart(messageBodyPart2);
  167.  
  168. Transport.send(message);
  169.  
  170. System.out.println("Done");
  171.  
  172. } catch (MessagingException e) {
  173. throw new RuntimeException(e);
  174. }
  175. }
  176. catch( Exception e )
  177. {
  178. e.printStackTrace();
  179. }
  180. }
Add Comment
Please, Sign In to add comment