Home > Enterprise >  Spring Boot & Spring boot Admin Can't sent alert email from Docker container
Spring Boot & Spring boot Admin Can't sent alert email from Docker container

Time:12-10

Here in my company we are trying to stablish a micro service based environment, where all the micro services to come will be monitored by an actuator application. We've created two applications, the first micro service and the spring boot admin project, locally all went well and all, then we used docker on this two applications, a container for each one and here start the problems.

Both applications run on port 8080 inside the container, then we assign an external port for its access, this seems to affect the way actuator communicates because now I'm having issues when the client application goes down, the admin is not sending any emails alerting as it did when locally. Here're my configs (changing some parameters):

Client:

.properties:

server.port=8080
spring.boot.admin.client.instance.name=Monitoramento Catracas
spring.boot.admin.client.url=http://my-ip:6060
spring.boot.admin.client.instance.service-base-url=http://my-ip:7070

docker-compose.yml:

services:
  my-service:
    build:
      context: ./
      dockerfile: my-file.dockerfile
    image: test/my-image
    container_name: my-container
    ports:
       - 7070:8080

Spring Boot Admin Application:

.properties

spring.mail.host=smtp.office365.com
spring.mail.port=587
spring.mail.username=email@email
spring.mail.password=12345
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true    

server.port=6060
spring.boot.admin.notify.mail.enabled=true
spring.boot.admin.notify.mail.from=email@email
spring.boot.admin.notify.mail.to=email_2@email
spring.boot.admin.notify.mail.template=classpath:templates/email-template.html

docker-compose.yml:

services:
  ms-admin:
    build:
      context: ./ms-admin
      dockerfile: ms-admin.dockerfile
    image: cap/ms-admin
    container_name: ms-admin
    ports:
       - 6060:8080

And this is what I get when I turn off the client application:

2022-12-09 17:06:10.534  WARN 1 --- [or-http-epoll-3] d.c.b.a.s.notify.NotificationTrigger     : Couldn't notify for event InstanceStatusChangedEvent(super=InstanceEvent(instance=2cc8546ac366, version=4, timestamp=2022-12-09T17:06:10.275Z, type=STATUS_CHANGED), statusInfo=StatusInfo(status=OFFLINE, details={exception=org.springframework.web.reactive.function.client.WebClientRequestException, message=finishConnect(..) failed: Connection refused: /my-ip:7070; nested exception is io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: /my-ip:7070}))
ms-monitoramento-hml |
ms-monitoramento-hml | org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1;
ms-monitoramento-hml |   nested exception is:
ms-monitoramento-hml |  java.net.UnknownHostException: smtp.office365.com. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1;
ms-monitoramento-hml |   nested exception is:
ms-monitoramento-hml |  java.net.UnknownHostException: smtp.office365.com


ms-monitoramento-hml | Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1
ms-monitoramento-hml |  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2210) ~[jakarta.mail-1.6.7.jar!/:1.6.7]
ms-monitoramento-hml |  at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:722) ~[jakarta.mail-1.6.7.jar!/:1.6.7]
ms-monitoramento-hml |  at javax.mail.Service.connect(Service.java:342) ~[jakarta.mail-1.6.7.jar!/:1.6.7]
ms-monitoramento-hml |  at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:518) ~[spring-context-support-5.3.23.jar!/:5.3.23]
ms-monitoramento-hml |  at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:437) ~[spring-context-support-5.3.23.jar!/:5.3.23]
ms-monitoramento-hml |  ... 124 common frames omitted

Hope someone can help me with this one, thanks

CodePudding user response:

In host, open terminal, and run

telnet smtp.office365.com 587

you will see message like

$ telnet smtp.office365.com 587
Trying 52.98.74.178...
Connected to HND-efz.ms-acdc.office.com.
Escape character is '^]'.
220 TYAPR01CA0154.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sat, 10 Dec 2022 09:25:14  0000

If not, means your host can't connect to mail server , not docker problem.

If you can see message (means Host is ok to connect to mail server) , then try

docker run -it yourDockerImage sh,

In container, open terminal, and run

telnet smtp.office365.com 587

you should see connect message.

CodePudding user response:

$ telnet smtp.office365.com 587 Trying 52.98.74.178... Connected to HND-efz.ms-acdc.office.com. Escape character is '^]'. 220 TYAPR01CA0154.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sat, 10 Dec 2022 09:25:14 0000

  • Related