Advertisement
Guest User

Untitled

a guest
Apr 1st, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <%@ page import="java.io.*,java.util.*,javax.mail.*"%>
  2. <%@ page import="javax.mail.internet.*,javax.activation.*"%>
  3. <%@ page import="javax.servlet.http.*,javax.servlet.*"%>
  4. <%@ page import="java.net.URLConnection,java.net.URL,org.apache.commons.io.IOUtils"%>
  5.  
  6. <%
  7.  
  8. URL url = new URL("http://fireforwire.appspot.com/Rankings.html");
  9. URLConnection con = url.openConnection();
  10. InputStream in = con.getInputStream();
  11. String encoding = con.getContentEncoding(); // ** WRONG: should use "con.getContentType()" instead but it returns something like "text/html; charset=UTF-8" so this value must be parsed to extract the actual encoding
  12. encoding = encoding == null ? "UTF-8" : encoding;
  13. String body = IOUtils.toString(in, encoding);
  14. System.out.println(body);
  15.  
  16. %>
  17.  
  18. <%
  19. out.println("Result: " + body + "n");
  20. %>
  21. <%
  22. String result;
  23.  
  24. Properties props = new Properties();
  25. props.put("mail.smtp.auth", "true");
  26. //props.put("mail.smtp.starttls.enable", "true");
  27. props.put("mail.smtp.host", "smtp.gmail.com");
  28. props.put("mail.smtp.port", "465");
  29. props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  30.  
  31. Session session1 = Session.getInstance(props,
  32. new javax.mail.Authenticator() {
  33. protected PasswordAuthentication getPasswordAuthentication() {
  34. return new PasswordAuthentication("sasipudi@gmail.com", "****");
  35. }
  36. });
  37.  
  38. try {
  39.  
  40. Message message = new MimeMessage(session1);
  41. message.setFrom(new InternetAddress("sasipudi@gmail.com"));
  42. message.setRecipients(Message.RecipientType.TO,
  43. InternetAddress.parse("sasipudi@gmail.com"));
  44. message.setSubject("Testing Subject");
  45. message.setContent(body, "text/html");
  46.  
  47. Transport.send(message);
  48.  
  49. System.out.println("Done");
  50. result="sent succesful";
  51.  
  52. } catch (MessagingException e) {
  53. throw new RuntimeException(e);
  54. }
  55.  
  56.  
  57. %>
  58.  
  59. <%
  60. out.println("Result: " + result + "n");
  61. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement