gessnerfl / fake-smtp-server

A simple SMTP Server for Testing purposes. Emails are stored in an in-memory database and rendered in a Web UI
Apache License 2.0
437 stars 90 forks source link

Cannot connect to smtp server running in docker container #168

Closed dangngoctam00 closed 1 year ago

dangngoctam00 commented 1 year ago

I've created a docker-compose file like this:

version: '2'
services:
  fakesmtp:
    image: gessnerfl/fake-smtp-server:latest
    container_name: fakesmtp
    hostname: fakesmtp
    environment:
      FAKESMTP_PORT: "1025"
      FAKESMTP_BIND_ADDRESS: "127.0.0.1"
    ports:
      - "8090:8080"
      - "8091:8081"
      - "1025:1025"

After running, the log of container looks fine and SMTP started at port 1025.

fakesmtp  | 2023-05-04T10:54:49.569Z  INFO 1 --- [           main] d.g.fakesmtp.smtp.server.BaseSmtpServer  : SMTP server /127.0.0.1:1025 starting
fakesmtp  | 2023-05-04T10:54:49.574Z  INFO 1 --- [/127.0.0.1:1025] d.g.fakesmtp.smtp.server.ServerThread    : SMTP server /127.0.0.1:1025 started
fakesmtp  | 2023-05-04T10:54:49.685Z  WARN 1 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
fakesmtp  | 2023-05-04T10:54:49.851Z  INFO 1 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
fakesmtp  | 2023-05-04T10:54:49.969Z  WARN 1 --- [           main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)
fakesmtp  | 2023-05-04T10:54:50.332Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
fakesmtp  | 2023-05-04T10:54:50.393Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
fakesmtp  | 2023-05-04T10:54:50.394Z  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
fakesmtp  | 2023-05-04T10:54:50.394Z  INFO 1 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.8]
fakesmtp  | 2023-05-04T10:54:50.403Z  INFO 1 --- [           main] o.a.c.c.C.[Tomcat-1].[localhost].[/]     : Initializing Spring embedded WebApplicationContext
fakesmtp  | 2023-05-04T10:54:50.403Z  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 68 ms
fakesmtp  | 2023-05-04T10:54:50.417Z  INFO 1 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 15 endpoint(s) beneath base path '/actuator'
fakesmtp  | 2023-05-04T10:54:50.460Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8081 (http) with context path ''
fakesmtp  | 2023-05-04T10:54:50.478Z  INFO 1 --- [           main] de.gessnerfl.fakesmtp.Application        : Started Application in 6.15 seconds (process running for 6.468)
fakesmtp  | 2023-05-04T10:54:51.025Z  INFO 1 --- [     task-pool1] d.g.f.service.EmailRetentionTimer        : Deleted 0 emails which exceeded the maximum number 100 of emails to be store

But I cannot connect to server by spring-boot application or telnet client. The error from Spring is [JavaMail: MessagingException: Got bad greeting from SMTP host: EOF, and error from telnet is Connection closed by foreign host. I've tried many times but it still hasn't worked. I think there is some error with smtp server. Thank you.

dangngoctam00 commented 1 year ago

This is my mistake, after some researching, I've found that if I provide FAKESMTP_BIND_ADDRESS env, server socket only allow connection from same network interface. So if I use docker to run fake-stmp server, I should remove this env.