Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swiftmailer / Mailhog #2279

Closed
shaneparsons opened this issue Sep 12, 2019 · 1 comment
Closed

Swiftmailer / Mailhog #2279

shaneparsons opened this issue Sep 12, 2019 · 1 comment

Comments

@shaneparsons
Copy link

shaneparsons commented Sep 12, 2019

Info:

  • Docker version: 19.03.2
  • Laradock commit: cb910c590e00cee77ebbf75867aae0c7d0199119
  • System info: macOS
  • System info disto/version: 10.14.4

Issue:


Perhaps related to #2039, ever since I switched a project from Homestead to Laradock, I havn't been able to send emails... Is the issue perhaps with Swiftmailer? Is Swiftmailer included with Laradock?

Exception:

Swift_TransportException: Connection could not be established with host localhost [Cannot assign requested address #99] in /var/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269

Expected behavior:


Emails to send, like they were in Homestead.

Reproduce:


Try sending an email (feel free to use my code below). The exception I got was through Horizon.

Relevant Code:

.env

QUEUE_CONNECTION=redis
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=notifications@laravel.test
MAIL_FROM_NAME=Laravel

App/Mail/Test.php

<?php

namespace App\Mail;

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

class GrantAdded extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'))
            ->subject('Test')
            ->markdown('emails.test');
    }
}

resources/views/emails/test.blade.php

@component('mail::message')
# Test

This is a test.
@endcomponent
@shaneparsons
Copy link
Author

Hmm, it seems to work now after running docker-compose restart...

The only thing I can think of is perhaps my change from MAIL_HOST=localhost to MAIL_HOST=mailhog hadn't fully registered and the restart fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant