如何在 wildfly swarm 中为 SMTP 邮件配置出站套接字绑定以使用 yaml?

How to configure outbound-socket-binding for SMTP mail in wildfly swarm for using yaml?

我正在将应用程序从 Wildfly 10.0.1.0 移植到 Wildly Swarm 2017.7.0。

除了使用 YAML 的 SMTP 电子邮件配置外,一切都很顺利:

我尝试了一些替代方案,但这是基于我认为 yaml 来自 standalone.xml 映射的最新方案 - project-defaults.yml

swarm:
  socket-binding-groups:
    mail-socket:    
      outbound-socket-bindings:
        mail-smtp:
          remote-host: smtp.someprovider.com
          remote-port: 587

  mail:
    mail-sessions:
      smtpSession:
        jndi-name: java:/smtpSession
        smtp-server:
          username: username_here
          password: password_here
          tls: true
          outbound-socket-binding-ref: mail-smtp

但是我仍然得到错误:

2017-08-05 11:17:36,100 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "mail"),
("mail-session" => "smtpSession") 
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.outbound-socket-binding.mail-smtp"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.mail-session.smtpSession is missing [jboss.outbound-socket-binding.mail-smtp]"]
}
2017-08-05 11:17:36,155 INFO  [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0184:    New missing/unsatisfied dependencies:
  service jboss.outbound-socket-binding.mail-smtp (missing) dependents: [service jboss.mail-session.smtpSession] 

---------------- 2017 年 8 月 7 日编辑--------------------

根据 Ladicek 的建议,我尝试了这个:

 swarm:
   socket-binding-groups:
     standard-sockets:
       mail-socket:
         outbound-socket-bindings:
           mail-smtp:
             remote-host: smtp.someprovider.com
             remote-port: 587

swarm:
  socket-binding-groups:
    standard-sockets:
      outbound-socket-bindings:
        mail-smtp:
          remote-host: smtp.someprovider.com
          remote-port: 587

swarm:
  socket-binding-groups:
    standard-socket:
      outbound-socket-bindings:
        mail-smtp:
          remote-host: smtp.someprovider.com
          remote-port: 587

但是两者都不工作,仍然有同样的错误。

有人可以帮忙吗?

--------------------解决了-------------------- ------

需要升级到2017.8.1并使用以下配置

network:
  socket-binding-groups:
    standard-sockets:
      outbound-socket-bindings:
        mail-smtp:
          remote-host: smtp.someprovider.com
          remote-port: 587

谢谢。

从我的头顶来看,我相信您缺少一级 YAML 结构:您需要 select 添加套接字绑定的套接字绑定组。那是 WildFly 托管域的产物,这是一个不适用于 Swarm 的概念,但您有时会 运行 进入它。在独立的 WildFly 中只有一个套接字绑定组,因此在 Swarm 中:standard-sockets.

因此 YAML 将如下所示:

swarm:
  socket-binding-groups:
    standard-sockets:
      mail-socket:
        ...

关于 Swarm YAML 结构的任何类型的问题,请咨询 https://reference.wildfly-swarm.io

终于解决了:

需要升级到2017.8.1并使用以下配置

network:
  socket-binding-groups:
    standard-sockets:
      outbound-socket-bindings:
        mail-smtp:
        remote-host: smtp.someprovider.com
        remote-port: 587

谢谢。

这对我有用。

yml 文件:

swarm:
  mail:
    mail-sessions:
      mail-socket:
        jndi-name: java:/mail/NGSoftMail
        smtp-server:
          username: sigafco@xxxmail.com.co
          password: *****
          outbound-socket-binding-ref: mail-smtp
        debug: true
        from: sigafco@xxxmail.com.co 

  network:
    socket-binding-groups:
      standard-sockets:
        outbound-socket-bindings:
          mail-smtp:
            remote-host: xxxmail.com.co
            remote-port: 25

java 文件:

@ApplicationScoped
@Path("mailsender")
public class MailSender {

  @Resource(mappedName = "java:/mail/NGSoftMail")
  private Session session;

  @GET
  @Path("mail")
  public String sendGet() throws Exception {
    Message message = new MimeMessage(session);

    message.setFrom();
    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("david.vasquez@xxx.com.co", false));
    message.setSubject("asunto!!!");
    message.setSentDate(new Date());
    message.setContent("contenido!!!", "text/html; charset=UTF-8");

    Transport.send(message);

    return String.format("{\"your_mail\": \"%s\"}", "OK");
  }
}

pom 文件:

<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>mail</artifactId>
</dependency>