1

I've tried all the possible solutions available here in stackoverflow, however nothing... I think the problem is related to the firewall, I can send mail using SMTP gmail on my local machine, but not in my server, I get the following message:

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

I've tried the following commands:

ufw allow 587/tcp

iptables -I OUTPUT -p tcp --dport 587 -j DROP

iptables -I OUTPUT -d smtp.gmail.com -p tcp -m tcp --dport 587 -j ACCEPT

iptables -L OUTPUT -n

However not worked...

This is my .env email settings:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=*****@gmail.com
MAIL_PASSWORD=*****
MAIL_ENCRYPTION=tls

My controller for sending emails:

public function postEmail(PostEmailRequest $request)
{
    if ($request){
        Mail::send('app.pages.contato.email', $request->all(), function($message) use ($request)
        {
            $message->from($request->email , config('settings.website_title'));
            $message->to(config('settings.admin_email'))->subject($request->assunto);
        });

        return redirect('contato');
    }else{
        return redirect('contato')->withErrors($request);
    }
}
Caio Kawasaki
  • 2,894
  • 6
  • 33
  • 69
  • And you say it works on your localhost? – Derek Pollard Jan 07 '16 at 18:22
  • See my answer below and tell me if it works for you – Derek Pollard Jan 07 '16 at 18:27
  • gmail blocks some hosts (e.g. i know that servers at one.com have some issues). Can you `telnet smtp.gmail.com 587`? If not, you may need to go with another mail provider, such as mailgun or mandrill. – patricus Jan 08 '16 at 01:01
  • @patricus really? Digital ocean is blocked? – Caio Kawasaki Jan 08 '16 at 01:06
  • It may be DO blocking it. According to [this QA](https://www.digitalocean.com/community/questions/why-my-server-can-t-connect-to-gmail-smtp), "To curb a recent increase in abuse and SPAM, DO has an initial SMTP block on new accounts created in certain contexts. If you file a support ticket (https://cloud.digitalocean.com/support) the team should be able to lift that for you after some manual account verification." – patricus Jan 08 '16 at 01:17
  • Other posts also say that DO doesn't support IPv6 for smtp, so you need to make sure you're using IPv4. In your `config/mail.php`, try wrapping the 'host' value with `gethostbyname()`. For example: `'host' => gethostbyname(env('MAIL_HOST', 'smtp.mailgun.org')),` – patricus Jan 08 '16 at 01:39
  • @patricus gethostbyname() do not work – Caio Kawasaki Jan 08 '16 at 01:53
  • Worth a shot. I'm guessing you'll need to submit a support ticket to DO. – patricus Jan 08 '16 at 02:04
  • @patricus I'll do it – Caio Kawasaki Jan 08 '16 at 02:04
  • Let us know what they say. It may be helpful for others, as well. – patricus Jan 08 '16 at 06:41

6 Answers6

2

I sent a ticket to Digital ocean and that is the obtained answer:

Hello!

To curb a recent increase in abuse and SPAM, we have an initial SMTP block on new accounts created in certain contexts.

To remove that block we'd like to do some manual account verification.

Please let us know the following:

  • Your Name
  • Location
  • Phone Number
  • The reason you are requesting the removal of the SMTP block

Also, please provide as many of the following as you can to help us verify your identity:

  • Your public Twitter handle
  • Your blog
  • Your company or personal website
  • Your public Facebook profile

We take SPAM very seriously as we comply fully with the CAN-SPAM Act. If you're not familiar, this says that you may not send bulk email unless you maintain a double-authorized list of subscribed members including IP addresses and relevant contact information. Also, you must follow guidelines for including removal links with all sent emails according to the CAN-SPAM Act.

If you have any questions we're happy to help answer them for you.

Regards, DigitalOcean Support

Edit


I replied with the information that was requested and now everything works perfectly =)

Caio Kawasaki
  • 2,894
  • 6
  • 33
  • 69
0

Have you tried the following:

.env:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=username@example.com
MAIL_PASSWORD=pass

and mail.php:

'encryption' => 'ssl',
Derek Pollard
  • 6,953
  • 6
  • 39
  • 59
0

You need to enable access for less secure applications google

https://www.google.com/settings/security/lesssecureapps

Abdou Tahiri
  • 4,338
  • 5
  • 25
  • 38
0

First of all check in gmail account if it allow to send email less secure apps. https://support.google.com/accounts/answer/6010255?hl=en

George Khachidze
  • 89
  • 1
  • 1
  • 6
0

Try to activate your account app password

https://accounts.google.com/b/0/DisplayUnlockCaptcha

To learn more: https://accounts.google.com/UnlockCaptcha

hbakouane
  • 21
  • 1
  • 5
  • Welcome to stack overflow. Can you please explain what is in the link? Your answer must remain valid even if the link expires. – LuizZ Dec 05 '20 at 22:57
  • This link will surely solve this problem, and will always work because it is provided by google – hbakouane Dec 05 '20 at 23:06
-1

I had similar issue with my laravel 5.3 app. My error was with self signed certificate on server. Solution here - https://stackoverflow.com/a/41267848

add to your config/mail.php this code somewhere

'stream' => [
    'ssl' => [
        'allow_self_signed' => true,
        'verify_peer' => false,
        'verify_peer_name' => false,
    ],
],
Community
  • 1
  • 1
Pavel Berka
  • 119
  • 2
  • 4
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](http://meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted](http://stackoverflow.com/help/deleted-answers). – mrun May 17 '17 at 10:48