【问题标题】:play framework 2.5 gmail can not send email into prod server播放框架 2.5 gmail 无法将电子邮件发送到 prod 服务器
【发布时间】:2017-07-02 04:11:02
【问题描述】:

你好孩子们。我有一个带有播放框架的开源项目,我有一个问题 intp 生产服务器。进入本地主机,播放发送正确的电子邮件,但在生产服务器中出现错误:

2017-07-01 17:12:09,274 [DEBUG] 来自 application-akka.actor.default-dispatcher-19 中的 com.sun.mail.smtp - 尝试连接到主机“smtp.gmail.com”, 465端口,isSSL false

2017-07-01 17:12:09,279 [DEBUG] 来自 application-akka.actor.default-dispatcher-19 中的 com.sun.mail.util.socket - getSocket,主机 smtp.gmail.com,端口 587 , 前缀mail.smtp, 使用SSL false

2017-07-01 17:12:09,473 [DEBUG] 来自 application-akka.actor.default-dispatcher-19 中的 com.sun.mail.smtp - 连接到主机“smtp.gmail.com”,端口: 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] 行[0] 名称[] 谓词[t0.email = ? ] 绑定[xxx@xxx]

2017-07-01 18:12:37,641 [DEBUG] 来自 application-akka.actor.default-dispatcher-94 中的 com.sun.mail.smtp - 尝试连接到主机“smtp.gmail.com”,端口 587,isSSL 错误 2017-07-01 18:12:37,641 [DEBUG] 来自 application-akka.actor.default-dispatcher-94 中的 com.sun.mail.util.socket - getSocket,主机 smtp.gmail.com,端口 465,前缀邮件.smtp,使用SSL false

2017-07-01 18:12:37,802 [DEBUG] 来自 application-akka.actor.default-dispatcher-94 中的 com.sun.mail.smtp - 连接到主机“smtp.gmail.com”,端口: 465

存储库在此处可用:https://bitbucket.org/companystalker/com.silenceonthewire

你能帮帮我吗?什么鬼?

【问题讨论】:

  • 换句话说,您在问为什么您没有向我们展示的代码没有按预期工作。这是一个非常难以回答的问题,您可能希望通过在您的问题中发布您的Minimal, Complete, and Verifiable examplecode 来使其更容易回答。

标签: java playframework gmail


【解决方案1】:

我的 SSL 代码是:

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);
        }
    }

}

和配置是:

# 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 = "silenceonthewire.contact@gmail.com"
mail.password = ""

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

play.filters.csrf.bypassCorsTrustedOrigins = false

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 2015-10-15
    相关资源
    最近更新 更多