s-ichikawa/laravel-sendgrid-driver

Not working after upgrade to Laravel 8.6.0

venom1979 opened this issue · 6 comments

After upgrading my application to Laravel 8.6, I'm getting this error when I try to send email using Sendgrid:

  Swift_TransportException

  Connection could not be established with host sendgrid.net :stream_socket_client(): unable to connect to tcp://sendgrid.net:587 (Connection refused)

  at vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269
    265▕         }
    266▕         $streamContext = stream_context_create($options);
    267▕
    268▕         set_error_handler(function ($type, $msg) {
  ➜ 269▕             throw new Swift_TransportException('Connection could not be established with host '.$this->params['host'].' :'.$msg);
    270▕         });
    271▕         try {
    272▕             $this->stream = stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
    273▕         } finally {

  1   [internal]:0
      Swift_Transport_StreamBuffer::{closure}("stream_socket_client(): unable to connect to tcp://sendgrid.net:587 (Connection refused)", "/laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php")

Are you aware of any compatibility issues with this package and Laravel 8?

Seems the latest version of laravel is v8.0.3 now.
https://github.com/laravel/laravel/releases

Can you tell me an accurate version?

And this library does not use StreamBuffer class.
Is it set sendgrid to MAIL_DRIVER?
see: https://github.com/s-ichikawa/laravel-sendgrid-driver#configure

Seems the latest version of laravel is v8.0.3 now.
https://github.com/laravel/laravel/releases

Can you tell me an accurate version?

According to vendor\laravel\framework\src\Illuminate\Application.php:

    /**
     * The Laravel framework version.
     *
     * @var string
     */
    const VERSION = '8.6.0';

using PHP artisan --version gives the same result. I would have to assume that this is the accurate version?

Here is a link from Laravel News about the release of 8.6: https://laravel-news.com/laravel-8-6-0

And this library does not use StreamBuffer class.
Is it set sendgrid to MAIL_DRIVER?
see: https://github.com/s-ichikawa/laravel-sendgrid-driver#configure

MAIL_DRIVER was replaced with MAIL_MAILER as of Laravel 7. I believe I changed it to smtp by mistake. Setting it to 'sendgrid' changes the error:

   InvalidArgumentException

  Unsupported mail transport [].

  at vendor/laravel/framework/src/Illuminate/Mail/MailManager.php:172
    168▕             return call_user_func($this->customCreators[$transport], $config);
    169▕         }
    170▕
    171▕         if (trim($transport) === '' || ! method_exists($this, $method = 'create'.ucfirst($transport).'Transport')) {
  ➜ 172▕             throw new InvalidArgumentException("Unsupported mail transport [{$transport}].");
    173▕         }
    174▕
    175▕         return $this->{$method}($config);
    176▕     }

      +6 vendor frames

Here are the relevant .env settings on my app:

MAIL_MAILER=sendgrid
MAIL_HOST=sendgrid.net
MAIL_PORT=587
MAIL_USERNAME='username redacted'
MAIL_PASSWORD='password redacted'
MAIL_ENCRYPTION=tls
SENDGRID_API_KEY='api key redacted'

Thanks for your help!

using PHP artisan --version gives the same result. I would have to assume that this is the accurate version?

Oh, sorry I misunderstood the version of laravel-app and laravel-framework.

And that errors may be by miss-configuration in config/mail.php.
Please check to exists following in the file.

    'mailers' => [
        ...
        'sendgrid' => [
            'transport' => 'sendgrid',
        ],

using PHP artisan --version gives the same result. I would have to assume that this is the accurate version?

Oh, sorry I misunderstood the version of laravel-app and laravel-framework.

And that errors may be by miss-configuration in config/mail.php.
Please check to exists following in the file.

    'mailers' => [
        ...
        'sendgrid' => [
            'transport' => 'sendgrid',
        ],

That was it! Had to add transport to the mailer array for sendgrid. Working perfectly now, thanks!