Sam-R / laravel-docker-dev

A PHP MySQL docker compose setup for local development
6 stars 3 forks source link

About MailHog service #1

Closed zacktagnan closed 4 years ago

zacktagnan commented 4 years ago

Hi Sam:

We were talking about how to configure the "docker-compose.yml" and the Laravel ".env" file on the chat of the Erika Heidi dockercon session (about "How to Create PHP Development Environments with Docker Compose") ... Maybe you remember our conversastion.

So, I download your repo and try it and the sending emails process works fine. No like mine. The configuration of my "docker-compose.yml" and ".env" is similar to yours, but, when I launch the process to send and email, I have this message error on the browser:

Connection could not be established with host 127.0.0.1 :stream_socket_client(): unable to connect to 127.0.0.1:1025 (Connection refused)

Do you know what is the reason of this error? I had the MAIL_HOST=127.0.0.1 but, after heard your advice, I changed it to the name of my Mailhog service name. But even with that, I also don't fix the error, even if I follow your suggestions and put the same MAIL environment variables on the ".env" file. The error I receive is the same.

On the other hand, I realize that you name the MailHog service like "mailhog", the same reference for MAIL_HOST, and another inside the Dockerfile:

[docker-compose.yml]

    mailhog:
        image: mailhog/mailhog

[Dockerfile.app]

RUN echo '\n\
host mailhog\n\
port 1025\n\
from php-dev@example.com\n' \
>> /etc/msmtprc

[.env] MAIL_HOST=mailhog

But, if the name of the services in the "docker-compose.yml" is a random personal choice, that is, that it is possible to put the name that you want to each service, then, if I replace "mailhog" with "mailhog_server" in the 3 references mentioned above, why the email sending process fails showing this error message?:

Connection could not be established with host mailhog :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known

...even if rebuild the "php" service image with this command when I up the services:

docker-compose up -d --build

Where can a reference to the previous term persist (which, supposedly, would no longer have to exist after the change mentioned in each of the 3 files), even after a reconstruction of the "php" service?

So, only it can works if the reference is "mailhog"? and it is impossible that works if it is apply another name? Why?

And, another more question ... Is it necessary to put the Mailhog lines on the Dockerfile so that there can be a communication between the PHP application and the MailHog server and therefore the emails are sent? If you don't put this lines on the Dockerfile, the email sending process doesn't work? Where did you get the idea of putting that MailHog reference into the Dockerfile? I have not seen anything like it in the MailHog documentation and much less, they say it is necessary.

I would appreciate receiving a response from you ... Best regards.

Sam-R commented 4 years ago
Connection could not be established with host 127.0.0.1 :stream_socket_client(): unable to connect to 127.0.0.1:1025 (Connection refused)

Do you know what is the reason of this error?

This error is generated when your (presumably) PHP docker container tries to connect to the SMTP server defined in your .env file and that connection fails due to the defined port/service not being open for communication.

A simpler version: your setup is trying to send an email to something that doesn't accept email.

In this case it's your local machine (127.0.0.1). This matches with what you had in your .env file MAIL_HOST=127.0.0.1. I would suggest that this is wrong, unless you're running your own SMTP server on your host machine (which I wouldn't reccomend for development).

Think of your environment a like this:

+-----+ +---------+ +-------+
|     | |         | |       |
| PHP | | MailHog | | MySQL |
|     | |         | |       |
+-----+ +---------+ +-------+
Docker Network
+---------------------------+
Host Machine

+---------------------------+
Host Network

Anything on the "Docker Network" should be able to talk to anything else on the docker network by container name.

Docker network containers can talk to the host machine (127.0.0.1), but the host machine can't talk to docker containers without their ports being exposed (done by -P or the ports: heading in docker-compose.yml).

In your case your docker container is trying to talk to the host (127.0.0.1), not another container. Because of this you can't catch mail with Mailhog.

If you change your .env for PHP/Larvel to talk to the name of the Mailhog container, it should work.

A caveat to this is that Docker can run multiple named networks. You'll see in my docker-compose file I've named the network laravel and every container is within this network.

If your configuration has the Mailhog container outside of the named Docker network the rest of the containers are in, it could affect communication because the two networks can't talk to eachother (based on my understanding).

 Docker Network

+-----------------------------+
|Docker "Laravel" Network     |
+------+             +--------+   +---------+
||     |             |       ||   |         |
|| PHP |             | MySQL ||   | MailHog |
||     |             |       ||   |   :-(   |
|------+             +--------|   +---------+
+-----------------------------+

+-----------------------------------------------------+
Host Machine

So, only it can works if the reference is "mailhog"? and it is impossible that works if it is apply another name?

No matter what you name your container for "mailhog" it should still work. I think you only need to change it in three places:

[docker-compose.yml]

    # Mailhug (Optional, mail-catcher)
    development-mail-catcher-service: # <---- I've renamed the "mailhog" container
        image: mailhog/mailhog
        networks:
            - laravel
        ports:
            - 8025:8025

Since docker-compose creates the container, it has to know what it calls it.

[Dockerfile.app]

# Setup msmtp for PHP mail() command (Replaces abandoned ssmtp package in Debian)
RUN echo '\n\
host development-mail-catcher-service\n\ # <---- I've renamed the "mailhog" container
port 1025\n\
from php-dev@example.com\n' \
>> /etc/msmtprc

RUN echo 'sendmail_path = /usr/bin/msmtp -t' >> /usr/local/etc/php/php.ini

I've built this image with a different SMTP package - see: https://github.com/mailhog/MailHog#sendmail

The idea is this catches all mail send by PHP's mail() function. You can delete this section from the Dockerfile.app if you want, it is not required if your .env is setup for Laravel.

[.env]

MAIL_MAILER=smtp
MAIL_HOST=development-mail-catcher-service # <---- I've renamed the "mailhog" container
MAIL_PORT=1025
MAIL_FROM_ADDRESS=test@example.com
MAIL_FROM_NAME="${APP_NAME}"

Since your PHP/Laravel application needs to know how to send emails to the container you need the MAIL_HOST to match.

I hope this helps you in some way. I am still learning Docker myself, so I may have mistakes in my setup or explanation.

zacktagnan commented 4 years ago

Hi Sam:

Thanks for your response. I didn't want to answer before doing some tests. Some of the questions I made you, were made after doing tests with your project.

With any changes, the sending process works fine. But, when I changed the "mailhog" reference used in "Dockerfile", "docker-compose.yml" and ".env" to, for example, with the name service like "mailhog_server", the sending process didn't work. At least, on my local computer.

I had do a lot of tests:

But ... what's happen? What is it that crazy thing? :) Finally, I find the important mistake ... If you know something about Laravel, with Artisan on the terminal, there is some command options to clear the cache of the project. So, I execute this terminal command using the APP service container, in your project, the "php" service:

docker-compose exec php php artisan config:cache Configuration cache cleared! Configuration cached successfully!

After that, it doesn't matter what is the name of the service: "mailhog", "mailhog_server" or whatever you want. The sending process works!!!! Yeah!!! And the same on my project. After cleaning the project cache. The sending process to MailHog works fine.

Only, it was necessary for that's work:

Yeah!! The emails sending process to MailHog, finally, it works !!!

But ... After, that I add another server fake mail configuration, MailDev (its GitHub and its Docker doc). And, on its configuration block, inside the .env, I don't make to point its MAIL_HOST_MDev=127.0.0.1 but MAIL_HOST_MDev=maildev being "maildev" the name of the service inside my "docker-compose.yml"

I also clean the project cache but the email sending to this one, to MailDev, I can't get it to work. I have the same error like always, now not with referenced to "host 127.0.0.1", like before, but referenced to "host maildev", even if the service name is like that "maildev". That is the error message I receive:

Connection could not be established with host maildev :stream_socket_client(): unable to connect to maildev:1025 (Connection refused)

Totally, I configure one to MailTrap (I have an account), a second to MailHog and a last one to MailDev. Now, it works, for me, with MailTrap and MailHog, but not work with MailDev, all through Docker Compose. Because, the curious thing if I execute my Laravel project without Docker, in my local develop environment (Windows.10.Enterprise-Apache-MySql-PHP), and the MailHog and the MailDev running with Docker, the emails sending process works fine to the one and to the another.

All, it was to test one of the new releases to the version 7.x of Laravel, the "Multiple Mail Drivers", you can watch a demo on this video (New in Laravel 7 - Multiple Mail Driver).

That's, now, my files:

[ docker-compose.yml ]

version: '3'

services:

  # PHP
  app:
    depends_on:
      - db_server
    build:
      context: ../__docker-img/php
      dockerfile: Dockerfile
    image: laravel-app-img
    container_name: cont_app_${COMPOSE_PROJECT_NAME}
    tty: true
    environment:
      SERVICE_NAME: app
      SERVICE_TAGS: dev
    working_dir: /var/www/html
    volumes:
      - ./:/var/www/html
      - ../__docker-vol/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - net

  # Nginx
  web_server:
    depends_on:
      - app
    image: nginx:alpine
    container_name: cont_web_server_${COMPOSE_PROJECT_NAME}
    tty: true
    ports:
      - '8084:80'
      - '773:443'
    volumes:
      - ./:/var/www/html
      - ../__docker-vol/nginx/conf.d/:/etc/nginx/conf.d/
      - ../__docker-vol/nginx/conf.d/ssl/:/etc/nginx/conf.d/ssl/
    networks:
      - net

  # Composer
  composer_php:
    image: composer
    container_name: cont_composer_${COMPOSE_PROJECT_NAME}
    working_dir: /app
    volumes:
      - ./:/app
    networks:
      - net

  # NodeJS
  node_js:
    image: node
    container_name: cont_node_js_${COMPOSE_PROJECT_NAME}
    working_dir: /var/www/html
    volumes:
      - ./:/var/www/html
    networks:
      - net

  # MySQL
  db_server:
    image: mysql:5.7.22
    container_name: cont_db_server_${COMPOSE_PROJECT_NAME}
    tty: true
    ports:
      #- '3306:3306'
      - '6606:3306'
    env_file: mysql.env
    environment:
      MYSQL_DATABASE: db_${DB_COMMON_DATA}
      MYSQL_USER: usu_${DB_COMMON_DATA}
      MYSQL_PASSWORD: xxxx_${DB_COMMON_DATA}
    volumes:
      - ../__docker-vol/mysql/my.cnf:/etc/mysql/my.cnf
      - ../__docker-vol/mysql/data:/var/lib/mysql/
    networks:
      - net

  # phpMyAdmin
  db_admin:
    depends_on:
      - db_server
    container_name: cont_db_admin_${COMPOSE_PROJECT_NAME}
    image: phpmyadmin/phpmyadmin
    ports:
      - '8094:80'
    env_file: phpmyadmin.env
    #--------------------------------------------------
    # Don't set this VOL if you haven't a conf.inc.php on local
    volumes:
      - ../__docker-vol/phpmyadmin/conf:/etc/phpmyadmin
    networks:
      - net

  # MailHog
  ####mailhog:
  mailhog_server:
    image: mailhog/mailhog
    container_name: cont_mailhog_server_${COMPOSE_PROJECT_NAME}
    tty: true
    ports:
      - '1025:1025'
      - '8025:8025'
    #restart: always
    restart: on-failure
    networks:
      - net

  # MailDev
  maildev:
    image: maildev/maildev
    container_name: cont_maildev_server_${COMPOSE_PROJECT_NAME}
    tty: true
    ports:
      - '1030:1025'
      - '1080:80'
    #restart: always
    restart: on-failure
    networks:
      - net

#Networks
networks:
  net:

[ Dockerfile ]

# Last version PHP right now
FROM php:7.4.5-fpm

ENV \
    DOCUMENT_ROOT=/var/www/html \
    USER_LRVL=www

WORKDIR $DOCUMENT_ROOT

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    #-> for 7.2-fm versions
    ##mysql-client \
    #-> for 7.3-fpm versions and thereafter
    # instead of using "mysql-client", it is used "mariadb-client"
    # but this, "default-mysql-client"
    default-mysql-client \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    #--------------------------------------------
    #added extensions to avoid errors
    libzip-dev \
    zlib1g-dev \
    #--------------------------------------------
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl

# Cleaning cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Installing extensions
#-> this ones don't work
##RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
##RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
#-> this another one doesn't work also
##RUN docker-php-ext-configure gd --with-gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ --with-png=/usr/include/
#-> this ones YES, they work
RUN docker-php-ext-install pdo_mysql zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd

# Adding user to the Laravel app
RUN groupadd -g 1000 $USER_LRVL
RUN useradd -u 1000 -ms /bin/bash -g $USER_LRVL $USER_LRVL

# Copiing the current folder to $DOCUMENT_ROOT
COPY . $DOCUMENT_ROOT

# Copiing permissions of the app folder
COPY --chown=$USER_LRVL:$USER_LRVL . $DOCUMENT_ROOT

# Replacing the current user by default (root) with this one, $USER_LRVL
USER $USER_LRVL

EXPOSE 9000

# Init the php-fpm server...
CMD ["php-fpm"]

[ .env ]

APP_NAME='Laravel 7.x :: News'
APP_ENV=local
APP_KEY=base64:OFe7irOEUvMPOfhRVxPObavnQD8W0jO2XhvJ68I/WA0=
APP_DEBUG=true
APP_URL=http://localhost

#---------------------------------------------------
#=====================================
#ADMIN USER DATA
#=====================================
SERVER_DOMAIN_DEFAULT=test.es
ADMIN_EMAIL_USERNAME_DEFAULT=admin-web
ADMIN_EMAIL_DEFAULT="${ADMIN_EMAIL_USERNAME_DEFAULT}@${SERVER_DOMAIN_DEFAULT}"
ADMIN_LEVEL_PROFILE_DEFAULT=1
#=====================================
#---------------------------------------------------

LOG_CHANNEL=stack

# DB_CONNECTION=mysql
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=

#MySQL ----------------------------------
MYSQL_ROOT_PASSWORD=12345678
DB_COMMON_DATA=lrvl_7x_news

DB_CONNECTION=mysql
#DB_HOST=127.0.0.1
    #by default, localhost
DB_HOST=db_server
    #the database server name, in this case,
    #it matchs with the name of the respective service
DB_PORT=3306
DB_DATABASE="db_${DB_COMMON_DATA}"
DB_USERNAME=root
DB_PASSWORD="${MYSQL_ROOT_PASSWORD}"

# For prefix the name project
# and suffix to the containers name
COMPOSE_PROJECT_NAME=lrvl_7x_news

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp

# MAIL_HOST=smtp.mailtrap.io
# MAIL_PORT=2525
# MAIL_USERNAME=null
# MAIL_PASSWORD=null
# MAIL_ENCRYPTION=null
#---------------------------------------------------
# MAIL_FROM_ADDRESS=null
# MAIL_FROM_NAME="${APP_NAME}"
#---------------------------------------------------
MAIL_FROM_ADDRESS="${ADMIN_EMAIL_DEFAULT}"
MAIL_FROM_NAME="${APP_NAME}"

#MailTrap::MTp
#-----------------------------------------------------
MAIL_HOST_MTp=smtp.mailtrap.io
MAIL_PORT_MTp=2525
#Data Account on "mailtrap.io" - Put yours if you have a MailTrap account
MAIL_USERNAME_MTp=xxxxxxxxxxxxxxxxxx
MAIL_PASSWORD_MTp=xxxxxxxxxxxxxxxxxx
MAIL_ENCRYPTION_MTp=null

#MailHog::MHg
#-----------------------------------------------------
#Not OK, it not work with this host name
#MAIL_HOST_MHg=127.0.0.1
#OK, with this host name
####MAIL_HOST_MHg=mailhog
#OK, with this host name also or with anotherelse
MAIL_HOST_MHg=mailhog_server
MAIL_PORT_MHg=1025
MAIL_USERNAME_MHg=null
MAIL_PASSWORD_MHg=null
MAIL_ENCRYPTION_MHg=null

#MailDev::MDev
#-----------------------------------------------------
#Not OK, it not work with this host name
#MAIL_HOST_MDev=127.0.0.1
#Even, Not OK, it not work with this host name also ... But why???
MAIL_HOST_MDev=maildev
####MAIL_HOST_MDev=maildev_server
# MAIL_PORT_MDev=25
#MAIL_PORT_MDev=1025
MAIL_PORT_MDev=1030
MAIL_USERNAME_MDev=null
MAIL_PASSWORD_MDev=null
MAIL_ENCRYPTION_MDev=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

[ mysql.env ]

MYSQL_ROOT_PASSWORD=12345678
DB_COMMON_DATA=lrvl_test

[ phpmyadmin.env ]

PMA_HOST=db_server
    #the database server name, in this case,
    #it matchs with the name of the respective service
#MySQL ----------------------------------
MYSQL_ROOT_PASSWORD=12345678

I think this are all the important configuration files Well, I config a simple process to send an email by a route:

[ ./routes/web.php ]

Route::get('/ejemplo-mailer', function () {
    // MTp-MailTrap :: MHg-MailHog :: MDv-MailDev
    $smtpAbbrevList = ['MTp', 'MHg', 'MDv'];
    $smtpAbbrev = '';
    /**
     * [00] - sending one to each server    >>    $i = 0; $i < count($smtpAbbrevList)
     * [01] - sending one to MTp and MHg    >>    $i = 0; $i < count($smtpAbbrevList) - 1
     * [02] - sending one to MTp only    >>    $i = 0; $i < count($smtpAbbrevList) - 2
     * [03] - sending one to MHg only    >>    $i = 1; $i < count($smtpAbbrevList) - 1
     * [04] - sending one to MDv only    >>    $i = 2; $i < count($smtpAbbrevList)
     */
    // [00]
    for($i = 0; $i < count($smtpAbbrevList); $i++) {
    // [01]
    ////for($i = 0; $i < count($smtpAbbrevList) - 1; $i++) {
    // [02]
    ////for($i = 0; $i < count($smtpAbbrevList) - 2; $i++) {
    // [03]
    ////for($i = 1; $i < count($smtpAbbrevList) - 1; $i++) {
    // [04]
    ////for($i = 2; $i < count($smtpAbbrevList); $i++) {

        if($smtpAbbrev == '') {
            $smtpAbbrev = $smtpAbbrevList[$i];
        } else {
            $smtpAbbrev = $smtpAbbrev . '-'.$smtpAbbrevList[$i];
        }

    }
    $emailTo = 'pep@test.com';
    $specialBye = ' ... OKiDOKi' . "-$smtpAbbrev";

    $objEmailData = new \stdClass();
    $objEmailData->to_name = 'Pep' . "-$smtpAbbrev";
    $objEmailData->msg_response = "Hi:

It is 21:07:00 ... What's up? How are you.
Come back soon.

REgards.$specialBye";
    $objEmailData->from_name = env('APP_NAME', 'XXXX');

    //Returning a response that the email is sending or NOT
    try {
        //Sending by MailTrap
        Mail::to($emailTo)->send(new TestMail($objEmailData));
        ////Mail::mailer('smtp')->to($emailTo)->send(new TestMail($objEmailData));
        //Alternative sending by MailHog
        Mail::mailer('smtp_mailhog')->to($emailTo)->send(new TestMail($objEmailData));
        //Alternative sending by MailDev
        Mail::mailer('smtp_maildev')->to($emailTo)->send(new TestMail($objEmailData));
        echo 'Response email ok sended'. $specialBye;
    } catch (\Exception $e) {
        ////echo 'ERRORMTp:: ' . $e->getMessage();
        echo "ERROR-$smtpAbbrev:: " . $e->getMessage();
    }
});

And the mailable file and the views are that ones:

[ TestMail.php, one mailable file you can create with Artisan ]

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class TestMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * The objResponseData object instance.
     *
     * @var ObjResponseData
     */
    public $objEmailData;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($objEmailData)
    {
        $this->objEmailData = $objEmailData;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.testmail_web')
                    ->text('emails.testmail_plain');
    }
}

[ emails.testmail_web ]

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{{ config('app.name', 'XxxX') }} :: Contact Response</title>
</head>
<body>
    [v.v] :: Aloha!! <i>{{ $objEmailData->to_name }}</i>

    <p><u>Message:</u></p>

    <div>
        <p>{!! nl2br($objEmailData->msg_response) !!}</p>
    </div>

    Thanks. See you next time,
    <br/>
    <i>{{ $objEmailData->from_name }}</i>
</body>
</html>

[ emails.testmail_plain ]

[v.t] :: Aloha!! {{ $objEmailData->to_name }}

Message:

{{ $objEmailData->msg_response }}

Thanks. See you next time,
{{ $objEmailData->from_name }}

Finally, that's all ... You can make all the test you want or not ... Or tell me what ever you want.

Sam-R commented 4 years ago

Since the problem is specific to the docker environment, I believe this is the bit in error:

[docker-compose.yml]

# MailDev
  maildev:
    image: maildev/maildev
    container_name: cont_maildev_server_${COMPOSE_PROJECT_NAME}
    tty: true
    ports:
      - '1030:1025'
      - '1080:80'
    #restart: always
    restart: on-failure
    networks:
      - net

Specifically the port binding:

      - '1030:1025'

These port bindings only work between host network and container network. Not between containers. You're basically allowing your host machine access to port 1025 in the maildev docker container.

I've had a look at their github and I think your maildev section needs to be:

[docker-compose.yml]

# MailDev
  maildev:
    image: maildev/maildev
    container_name: cont_maildev_server_${COMPOSE_PROJECT_NAME}
    tty: true
    ports:
      - '1080:80'
    #restart: always
    restart: on-failure
    networks:
      - net

Your Laravel .env environment also appears to need alterations:

[.env]

MAIL_HOST_MDev=maildev
MAIL_PORT_MDev=25 # <---- This is the port MailDev uses
MAIL_ENCRYPTION_MDev=null # <--- I needed to force TLS to be "null" to get it to work for my laravel instance

Two key things here:

1. MailDev Mail Port MAIL_PORT_MDev

When my docker enviornment was running, I couldn't get it to connec with your settings. Pretty confusing. I couldn't see anything in their docs about ports other than 1025 and that also didn't work. I used docker -ps and got this output:

1f973d4e3bf0        maildev/maildev                     "bin/maildev --web 8…"   9 minutes ago       Up 8 minutes        25/tcp, 0.0.0.0:1080->80/tcp        laravel-docker-dev_maildev_1

Notice port 25? That means MailDev is listening on port 25! So I changed my .env file MAIL_PORT_MDev to be on port 25 and that lead me to the next issue...

2. MailDev Encryption MAIL_ENCRYPTION_MDev This needs to be null. By default Laravel uses tls if it's not set in the .env. I was getting this error:

PHP Warning:  stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in /var/www/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 94

By setting MAIL_ENCRYPTION_MDev=null in .env it fixed it.

By changing these things I was able to send emails to both mailhog and maildev.

Oh and thanks, I didn't know you could use docker-compose exec php ..., I've been doing docker exec -it project-php_1 bash. Your way is much easier!

zacktagnan commented 4 years ago

Hi again:

Well, so finally the MailDev block inside the "docker-compose.yml" has to be like that:

MailDev

OK with this service name

maildev:

OK with this one also or whatever you want!!!! Yeah!!!

maildev_server: image: maildev/maildev container_name: cont_maildevserver${COMPOSE_PROJECT_NAME} tty: true ports:

And inside the ".env" file:

MailDev::MDev

-----------------------------------------------------

MAIL_HOST_MDev=maildev

MAIL_HOST_MDev=maildev_server MAIL_PORT_MDev=25 MAIL_USERNAME_MDev=null MAIL_PASSWORD_MDev=null MAIL_ENCRYPTION_MDev=null

I already had the "MAIL_ENCRYPTIO_MDev=null" but the other two things were wrong (the "port" inside the "docker-compose.yml" and the "MAIL_PORT_MDev" inside the ".env").

That's right now!!!I All email sending processes work!!! I'm very happy!!! :) And everything is thanks to you and your advices, finally After, almost, a month ago I was trying to solve that, searching by Internet, open issues on MailHog GitHub and MailDev without response or with one but not solution. And because of getting this session on Dockercon, I saw your project and your amability did the rest.

Thanks very much again!!!

Maybe you are, already, learning Docker by yourself. If you are searching for a good Docker course, this is a good one: Docker, From Zero To Hero: Become a DevOps Docker Master

Well, thanks again. See you. Have a nice week-end!!!

Best regards.

Sam-R commented 4 years ago

Excellent - glad it's working for you. I'll check out the course :-)

zacktagnan commented 4 years ago

One last question, with no strings attached ... I have no one specific, or no so much people to ask, personnaly, Docker questions like that. So may I ask you another time if I have any problem references to Docker? opening another issue or ... maybe by email? Do you know it there is, on GitHub, an email system to send an email to another user?

Bye!!

Sam-R commented 4 years ago

Good idea. Fair warning, I'm very bad at responding to people!

Twitter is @sir8472, pretty sure you'll be able to find my email address in the git repository if you poke around the commit history too ;-)