0
votes

hello boys. I have a open source project with play framework and I have a problem intp production server. Into localhost, play send correct emails but in production server I have error:

2017-07-01 17:12:09,274 [DEBUG] from com.sun.mail.smtp in application-akka.actor.default-dispatcher-19 - trying to connect to host "smtp.gmail.com", port 465, isSSL false

2017-07-01 17:12:09,279 [DEBUG] from com.sun.mail.util.socket in application-akka.actor.default-dispatcher-19 - getSocket, host smtp.gmail.com, port 587, prefix mail.smtp, useSSL false

2017-07-01 17:12:09,473 [DEBUG] from com.sun.mail.smtp in application-akka.actor.default-dispatcher-19 - connected to host "smtp.gmail.com", port: 465

2017-07-01 18:12:37,567 [DEBUG] from org.avaje.ebean.SUM in application-akka.actor.default-dispatcher-94 - txn[1007] FindMany type[UserModel] origin[D9IsfI.DfbUPF.x3-tY] exeMicros[933] rows[0] name[] predicates[t0.email = ? ] bind[xxx@xxx]

2017-07-01 18:12:37,641 [DEBUG] from com.sun.mail.smtp in application-akka.actor.default-dispatcher-94 - trying to connect to host "smtp.gmail.com", port 587, isSSL false 2017-07-01 18:12:37,641 [DEBUG] from com.sun.mail.util.socket in application-akka.actor.default-dispatcher-94 - getSocket, host smtp.gmail.com, port 465, prefix mail.smtp, useSSL false

2017-07-01 18:12:37,802 [DEBUG] from com.sun.mail.smtp in application-akka.actor.default-dispatcher-94 - connected to host "smtp.gmail.com", port: 465

The repository is available here: https://bitbucket.org/companystalker/com.silenceonthewire

Can you help me? WTF?

1
In other words, you're asking why the code you've not shown us not working as expected. This is a very difficult type of question to answer, and you might want to make it easier by posting your Minimal, Complete, and Verifiable examplecode with your question.Ivan Pronin

1 Answers

0
votes

My SSL code is:

package emails;

import play.Play;

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.HashMap;
import java.util.Properties;

/**
 * Created by adrian on 06.06.17.
 */
public class SendSslEmail {

    public void email(HashMap<String, String> email){
        Properties props = new Properties();
        props.put("mail.smtp.host", Play.application().configuration().getString("mail.smtp.host"));
        props.put("mail.smtp.socketFactory.port", Play.application().configuration().getString("mail.smtp.port"));
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", Play.application().configuration().getString("mail.smtp.auth"));
        props.put("mail.smtp.port", Play.application().configuration().getString("mail.smtp.port"));

        Session session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(
                                Play.application().configuration().getString("mail.username"),
                                Play.application().configuration().getString("mail.password")
                        );
                    }
                });

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(Play.application().configuration().getString("mail.username")));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(email.get("to")));
            message.setSubject(email.get("subject"));
            message.setText(email.get("content"));

            Transport.send(message);

            System.out.println("Done");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }

}

and config is:

# TLS settings
mail.smtp.auth = true
mail.smtp.starttls.enable = true
mail.smtp.socketFactory.port = 587
mail.smtp.host = "smtp.gmail.com"
mail.smtp.port = 465
mail.username = "[email protected]"
mail.password = ""

play.filters.csrf.header.bypassHeaders {
  X-Requested-With = "*"
  Csrf-Token = "nocheck"
}

play.filters.csrf.bypassCorsTrustedOrigins = false