Does Nette Enable TLS Encryption?

Notice: This thread is very old.
blsn
Member | 3
+
+1
-

Hi,

I use Nette Mail: Sending E-mails, in my Slim 3 application.
https://github.com/nette/mail

I use the following setting to send an email on my local server (Xampp).

$app = new \Slim\App([
	'settings' => [
		'displayErrorDetails' => true,
		'mailer' => [
		    'host' => 'smtp.gmail.com',
            'username' => 'myname@gmail.com',
            'password' => 'mypassword',
			'secure' => 'tls'
		],
	],
]);

I get the following error message:

Slim Application Error
The application could not run because of the following error:

Details

Type: Nette\Mail\SmtpException
Message: Unable to connect via TLS.
File: C:\xampp\htdocs\slim-auth-email\vendor\nette\mail\src\Mail\SmtpMailer.php
Line: 143
Trace

#0 C:\xampp\htdocs\slim-auth-email\vendor\nette\mail\src\Mail\SmtpMailer.php(80): Nette\Mail\SmtpMailer->connect()
#1 C:\xampp\htdocs\slim-auth-email\app\Controllers\Auth\AuthController.php(73): Nette\Mail\SmtpMailer->send(Object(Nette\Mail\Message))
#2 [internal function]: App\Controllers\Auth\AuthController->postSignUp(Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#3 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\Handlers\Strategies\RequestResponse.php(41): call_user_func(Array, Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#4 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\Route.php(344): Slim\Handlers\Strategies\RequestResponse->__invoke(Array, Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#5 C:\xampp\htdocs\slim-auth-email\app\Middleware\GuestMiddleware.php(17): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#6 [internal function]: App\Middleware\GuestMiddleware->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\Route))
#7 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\DeferredCallable.php(43): call_user_func_array(Object(App\Middleware\GuestMiddleware), Array)
#8 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\Route))
#9 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(73): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\Route))
#10 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(122): Slim\Route->Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#11 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\Route.php(316): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#12 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\App.php(476): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))
#13 C:\xampp\htdocs\slim-auth-email\app\Middleware\ValidationErrorsMiddleware.php(17): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#14 [internal function]: App\Middleware\ValidationErrorsMiddleware->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#15 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\DeferredCallable.php(43): call_user_func_array(Object(App\Middleware\ValidationErrorsMiddleware), Array)
#16 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#17 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(73): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Slim\App))
#18 C:\xampp\htdocs\slim-auth-email\app\Middleware\OldInputMiddleware.php(16): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#19 [internal function]: App\Middleware\OldInputMiddleware->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#20 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\DeferredCallable.php(43): call_user_func_array(Object(App\Middleware\OldInputMiddleware), Array)
#21 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#22 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(73): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#23 C:\xampp\htdocs\slim-auth-email\app\Middleware\CsrfViewMiddleware.php(22): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#24 [internal function]: App\Middleware\CsrfViewMiddleware->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#25 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\DeferredCallable.php(43): call_user_func_array(Object(App\Middleware\CsrfViewMiddleware), Array)
#26 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#27 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(73): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#28 C:\xampp\htdocs\slim-auth-email\vendor\slim\csrf\src\Guard.php(162): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#29 [internal function]: Slim\Csrf\Guard->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#30 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\DeferredCallable.php(43): call_user_func_array(Object(Slim\Csrf\Guard), Array)
#31 [internal function]: Slim\DeferredCallable->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#32 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(73): call_user_func(Object(Slim\DeferredCallable), Object(Slim\Http\Request), Object(Slim\Http\Response), Object(Closure))
#33 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\MiddlewareAwareTrait.php(122): Slim\App->Slim\{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response))
#34 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\App.php(370): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#35 C:\xampp\htdocs\slim-auth-email\vendor\slim\slim\Slim\App.php(295): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#36 C:\xampp\htdocs\slim-auth-email\public\index.php(5): Slim\App->run()
#37 {main}

jiri.pudil
Nette Blogger | 1029
+
+1
-

Hello there,

it might be a problem with the port: SmtpMailer apparently defaults to 465 for ssl and 25 for anything else, while Google runs the Gmail SMTP server on 587 for TLS. Try adding 'port' => 587 to the config.

blsn
Member | 3
+
0
-

Thank you for your reply,
'port' => 587 was added, still not work.

GEpic
Member | 566
+
0
-

Check if you have this port opened on your PC / Router if its from local. You may be behind firewall.

blsn
Member | 3
+
0
-

SOLVED:

Messed up TLS certificates intercepting SMTP traffic ..
needed to skip certificate validation checks when I run the code locally on my computer:

$app = new \Slim\App([
	'settings' => [
		'displayErrorDetails' => true,
		'mailer' => [
		    'host' 		=> getenv('MAIL_HOST'),
            'username' 	=> getenv('MAIL_USERNAME'),
            'password' 	=> getenv('MAIL_PASSWORD'),
			'secure' 	=> getenv('MAIL_ENCRYPTION'),
			'port' 		=> getenv('MAIL_PORT'),

			'context' =>  [
				'ssl' => [
					'verify_peer' => false,
					'verify_peer_name' => false,
					'allow_self_signed' => true
				]
			],

		],
		'baseUrl' => getenv('BASE_URL')
	],
]);