7

I want to send mail from my local machine using laravel 5.4 in a forget password API. But I am getting Swift_TransportException

(1/1) Swift_TransportException
Expected response code 220 but got code "502", with message "502 Command not implemented
"


The .env details is

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=username@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=username@gmail.com
MAIL_FROM_NAME=Project.com


The code I am getting error is

$response = $this->broker()->sendResetLink(
      $request->only('email')
);


The code in config/mail.php is

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'markdown' => [
        'theme' => 'default',

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

How can I enable mailing from my local machine? Does I have to enable port for that?

Salini L
  • 829
  • 5
  • 15
  • 43
  • 1
    You can not use Gmail SMTP like this as you have to use Auth 2.0 now – tam Jul 14 '17 at 12:05
  • Can you also share your `config/mail.php` (not the comments just the actual config) – apokryfos Jul 14 '17 at 12:26
  • @apokryfos I have updated the question with mail.php details. Please check it – Salini L Jul 14 '17 at 12:30
  • 1
    @Salini all I can say is I've tried the same configuration (with my own credentials) and it worked for me. The problem doesn't seem to be code related. If you're behind an organisation firewall they may be blocking outgoing requests to those ports or something like that. Of course I'm assuming you're not using 2-factor authentication on your account. Check your email in case there's any messages from google about blocking or unusual activity as well. – apokryfos Jul 14 '17 at 13:20
  • @apokryfos I have checked my gmail but not received such mail. I think organisation firewall may be the problem How can I clarify it? – Salini L Jul 16 '17 at 19:19
  • for firewall check this https://mediatemple.net/community/products/dv/204404564/checking-your-outgoing-mail-server-(is-port-25-blocked) – Kabir Hossain Aug 03 '17 at 10:47

3 Answers3

3

You can download and use fakesmtp http://nilhcem.com/FakeSMTP/ for localhost and set port :25 by default..for any framework its support for local server machines . Only you need to start whenever you want send mail and check the mails log in fakesmtp.

Devraj Gupta
  • 329
  • 3
  • 13
1

Just a thought:

Try use mailtrap.io on local development machine. It's easy to configure and laravel supports it out of the box. Shouldn't bother your production mail server during development.

Cheers!

Zeshan
  • 2,496
  • 3
  • 21
  • 26
0

try this configuration in .env file, it allways works for me.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=useraddress@gmail.com
MAIL_PASSWORD=userpassword
MAIL_ENCRYPTION=ssl

and configure your config/mail.php like so:

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

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],
    'stream' => [
        'ssl' => [
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false
        ]
    ]

ps: you'll need to configure your useraddress@gmail.com account to allow less secure application to use it

Omar Ajmi
  • 180
  • 1
  • 13