Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. -------------- EN API ----------------
  2.  
  3. @POST
  4. @Consumes({MediaType.APPLICATION_JSON})
  5. @Produces({MediaType.TEXT_PLAIN})
  6. @Path("/contactus")
  7. public int contactUsMessage(String input) throws Exception{
  8.  
  9. JsonReader jsonReader = Json.createReader(new StringReader(input));
  10. JsonObject jsonObj = jsonReader.readObject();
  11. jsonReader.close();
  12.  
  13. int success = Config.sendContactUsMessage(jsonObj);
  14.  
  15. if (success == 1)
  16. return SUCCESS_RESULT;
  17.  
  18. return FAILURE_RESULT;
  19. }
  20.  
  21.  
  22. ----------------------- EN CONFIG.JAVA ---------------------------
  23.  
  24. public static int sendContactUsMessage(JsonObject jsonObj) {
  25.  
  26. int output = 0;
  27.  
  28. Properties props = new Properties();
  29. props.put("mail.smtp.host", "smtp.gmail.com");
  30. props.put("mail.smtp.socketFactory.port", "465");
  31. props.put("mail.smtp.socketFactory.class",
  32. "javax.net.ssl.SSLSocketFactory");
  33. props.put("mail.smtp.auth", "true");
  34. props.put("mail.smtp.port", "465");
  35.  
  36. Session session = Session.getDefaultInstance(props,
  37. new javax.mail.Authenticator() {
  38. protected PasswordAuthentication getPasswordAuthentication() {
  39. return new PasswordAuthentication("devTeamSabana@gmail.com","passwordDevTeam123");
  40. }
  41. });
  42.  
  43. try {
  44.  
  45. Message message = new MimeMessage(session);
  46. message.setFrom(new InternetAddress("devTeamSabana@gmail.com"));
  47. message.setRecipients(Message.RecipientType.TO,
  48. InternetAddress.parse("devTeamSabana@gmail.com")); // Who receives this email (here should be sabana's mail
  49. message.setSubject("CONTACTUS - SABANA");
  50. message.setText(jsonObj.getString("ctus_first_name") + jsonObj.getString("ctus_last_name") + ") says:\n"
  51. + jsonObj.getString("ctus_content") + "\n\n" + "Full contact info:\nFirst Name: " + jsonObj.getString("ctus_first_name")
  52. + "\nLast Name: " + jsonObj.getString("ctus_last_name") + "\nEmail: " + jsonObj.getString("ctus_email") + "\n");
  53. Transport.send(message);
  54.  
  55. output = 1;
  56.  
  57. } catch (MessagingException e) {
  58. output = 0;
  59. }
  60. return output;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement