Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------- EN API ----------------
- @POST
- @Consumes({MediaType.APPLICATION_JSON})
- @Produces({MediaType.TEXT_PLAIN})
- @Path("/contactus")
- public int contactUsMessage(String input) throws Exception{
- JsonReader jsonReader = Json.createReader(new StringReader(input));
- JsonObject jsonObj = jsonReader.readObject();
- jsonReader.close();
- int success = Config.sendContactUsMessage(jsonObj);
- if (success == 1)
- return SUCCESS_RESULT;
- return FAILURE_RESULT;
- }
- ----------------------- EN CONFIG.JAVA ---------------------------
- public static int sendContactUsMessage(JsonObject jsonObj) {
- int output = 0;
- Properties props = new Properties();
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.socketFactory.port", "465");
- props.put("mail.smtp.socketFactory.class",
- "javax.net.ssl.SSLSocketFactory");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.port", "465");
- Session session = Session.getDefaultInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication("devTeamSabana@gmail.com","passwordDevTeam123");
- }
- });
- try {
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress("devTeamSabana@gmail.com"));
- message.setRecipients(Message.RecipientType.TO,
- InternetAddress.parse("devTeamSabana@gmail.com")); // Who receives this email (here should be sabana's mail
- message.setSubject("CONTACTUS - SABANA");
- message.setText(jsonObj.getString("ctus_first_name") + jsonObj.getString("ctus_last_name") + ") says:\n"
- + jsonObj.getString("ctus_content") + "\n\n" + "Full contact info:\nFirst Name: " + jsonObj.getString("ctus_first_name")
- + "\nLast Name: " + jsonObj.getString("ctus_last_name") + "\nEmail: " + jsonObj.getString("ctus_email") + "\n");
- Transport.send(message);
- output = 1;
- } catch (MessagingException e) {
- output = 0;
- }
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement