2

I'm trying to send email after user registration and I get an error:

Connection could not be established with host smtp.gmail.com [Connection timed out #110]

I'm using Ubuntu 16.04 server. Everything was ok on localhost.
Command

openssl s_client -connect google.com:443 -tls1_2

returns OK, so I guess 587 port is opened to send email.
My .env:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=***@gmail.com
MAIL_PASSWORD=*** //(not the same as I used on local machine)
MAIL_ENCRYPTION=tls

config\mail.php:

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

    'port' => env('MAIL_PORT', 587),

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '***@gmail.com'),
        'name' => env('MAIL_FROM_NAME', '***'),
    ],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

    'sendmail' => '/usr/sbin/sendmail -bs',

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

EDIT#1: also I have connected problem. While trying to seed this

public function run()
    {
        $defaultUser = User::create([
            'name' => 'user',
            'email' => 'user@mail.com',
            'password' => bcrypt('123123'),
            'verified' => 1
        ]);

        $defaultAdmin = User::create([
            'name' => 'admin',
            'email' => 'admin@mail.com',
            'password' => bcrypt('123123'),
            'verified' => 1
        ]);

        $userRole = Role::create([
            'name' => 'user',
            'display_name' => 'user',
            'description' => 'user',
        ]);

        $adminRole = Role::create([
            'name' => 'admin',
            'display_name' => 'admin',
            'description' => 'admin',
        ]);

        $defaultUser->attachRole($userRole); //zizaco-entrus RBAC package
        $defaultAdmin->attachRole($adminRole);
    }

only $defaultUser seeds (I have an event which fires after user is stored and send an verification mail to him). I get an error

In StreamBuffer.php line 269:

Connection could not be established with host smtp.gmail.com [Connection ti med out #110]

EDIT#2: telnet smtp.gmail.com 587 does not response.

EDIT#3: sudo ufw status:

Status: active

To                         Action      From
--                         ------      ----
Apache Full                ALLOW       Anywhere
587/tcp                    ALLOW       Anywhere
465/tcp                    ALLOW       Anywhere
22                         ALLOW       Anywhere
80                         ALLOW       Anywhere
443                        ALLOW       Anywhere
21/tcp                     ALLOW       Anywhere
587                        ALLOW       Anywhere
Apache Full (v6)           ALLOW       Anywhere (v6)
587/tcp (v6)               ALLOW       Anywhere (v6)
465/tcp (v6)               ALLOW       Anywhere (v6)
22 (v6)                    ALLOW       Anywhere (v6)
80 (v6)                    ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)
21/tcp (v6)                ALLOW       Anywhere (v6)
587 (v6)                   ALLOW       Anywhere (v6)

EDIT#4:
My new Gmail app key I created for this project is still unused.

I tried this answer:

In AbstractSmtpTransport.php line 419:
Expected response code 220 but got code "", with message ""

Also this answer didn't help.

EDIT#5: checked smtp permission on server dashboard. Sorry for disturbing guys.

1 Answers1

0

I have experience with GoDaddy servers that limit the number of relays your server can send out per day.

Google Cloud Platform prohibits the sending of emails altogether by blocking the commonly used SMTP email ports. They do have agreements with the saas email providers to raise the number of free emails you can send. For example, I use mailgun and instead of sending only 10,000 emails per month for free, I can send 30,000 emails. I really like sending the emails this way because they have higher deliverability and allow us to track clicks, unsubscribes, views, etc easier. Bottom line, I recommend subscribing to one of these services.

I suspect that Scaleway is limiting you as well. Basically, any cloud server hosting service has a liability with emails. Especially with shared hosting 1 spammer can flag multiple users across the same server and region as spammers even though they may be innocent.

ajon
  • 7,868
  • 11
  • 48
  • 86