Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2017
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. /*
  2. * This program will capture the issues of redmine projects and mails the same to intended user.
  3. * This is purely based on a "As-Is" standard, No Assurance or Warranty on its results, hence no claim entertained !
  4. * This program is strictly in use for internal purpose only !
  5. */
  6.  
  7. /**
  8. * This work is an infant, Valid suggestions are accepted ! :-)
  9. * @author: Bhaskar Kashyap : Email-id: bskr.ksyp9@gmail.com
  10. */
  11. import java.util.*;
  12. import javax.mail.*;
  13. import javax.mail.internet.*;
  14. import java.sql.*;
  15.  
  16.  
  17. public class SendMailSSL
  18. {
  19. public static void main(String [] args){
  20.  
  21.  
  22. String host = "smtp.gmail.com"; //change your host accordingly
  23. String to="XXX@gmail.com"; //change accordingly
  24. final String user="YYY@gmail.com";//change accordingly
  25. final String password="*********";//change accordingly
  26.  
  27. //Some properties & session objects
  28. Properties properties = System.getProperties();
  29. properties.setProperty("mail.smtp.starttls.enable", "true");
  30. properties.setProperty("mail.smtp.host", host);
  31. properties.put("mail.smtp.host", "smtp.gmail.com");
  32. properties.put("mail.smtp.socketFactory.port", "587");
  33. properties.put("mail.smtp.socketFactory.class",
  34. "javax.net.ssl.SSLSocketFactory");
  35. properties.put("mail.smtp.auth", "true");
  36. properties.put("mail.smtp.port", "587");
  37.  
  38. Session session = Session.getDefaultInstance(properties,
  39. new javax.mail.Authenticator() {
  40. @Override
  41. protected PasswordAuthentication getPasswordAuthentication() {
  42. return new PasswordAuthentication(user,password);
  43. }
  44. });
  45. //compose your message here
  46. try{
  47. Class.forName("com.mysql.jdbc.Driver");
  48. Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bitnami_redmine","root","123123123");
  49.  
  50.  
  51. MimeMessage message = new MimeMessage(session);
  52.  
  53. message.setFrom(new InternetAddress(user));
  54. message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
  55. message.setSubject("Redmine Issues");
  56. Statement stmt=con.createStatement();
  57. Statement stmt2=con.createStatement();
  58. Statement stmt3=con.createStatement();
  59. Statement stmt4=con.createStatement();
  60. Statement stmt5=con.createStatement();
  61.  
  62. ResultSet rs=stmt.executeQuery("select count(*) from issues");
  63. ResultSet rs2=stmt2.executeQuery("select count(*) from issues where priority_id=4" );
  64. ResultSet rs3=stmt3.executeQuery("select count(*) from issues where priority_id=3" );
  65. ResultSet rs4=stmt4.executeQuery("select count(*) from issues where priority_id=2" );
  66. ResultSet rs5=stmt5.executeQuery("select count(*) from issues where priority_id=1" );
  67.  
  68. while(rs.next()&&rs2.next()&&rs3.next()&&rs4.next()&&rs5.next())
  69. {
  70. System.out.println(" Total issues = "+rs.getInt(1));
  71. System.out.println(" Issues are in Urgent = "+rs2.getInt(1));
  72. System.out.println(" Issues are in High = "+rs3.getInt(1));
  73. System.out.println(" Issues are in Normal = "+rs4.getInt(1));
  74. System.out.println(" Issues are in Low = "+rs5.getInt(1));
  75.  
  76. int msg = rs.getInt(1);
  77. int msg2 = rs2.getInt(1);
  78. int msg3 = rs3.getInt(1);
  79. int msg4 = rs4.getInt(1);
  80. int msg5 = rs5.getInt(1);
  81.  
  82. message.setContent("<h1>Open issues in Total = "+msg+"\n"+"<br><br>Issues are in Urgent = "+msg2+"<br>Issues are in High = "+msg3+"<br>Issues are in Normal = "+msg4+"<br>Issues are in Low = "+msg5+"</h1>", "text/html");
  83.  
  84. // Send message & display
  85. Transport.send(message);
  86. System.out.println("Mail sent Successfully...");
  87. }
  88. con.close();
  89. }
  90. catch (MessagingException mex) {
  91. mex.printStackTrace();
  92. }
  93. catch(Exception e){
  94. System.out.println(e);
  95. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement