Answer the question
In order to leave comments, you need to log in
How to properly configure Mailer to send mail to VPS?
Good afternoon,
The course of actions listed below was tested on a local machine and on a VPS hosting with DNS configured . Both here and there without an ssl certificate (only http://)
Firstly, the Laravel configuration , the options that I tried in turn:
1) Mail.ru
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mail.ru
MAIL_PORT=465
[email protected] en
MAIL_PASSWORD=secret_pass
MAIL_ENCRYPTION=tls
2) Gmail
#MAIL_DRIVER=smtp
#MAIL_HOST=smtp.gmail.com
#MAIL_PORT=587
#[email protected]
#MAIL_PASSWORD=secret_pass
#MAIL_ENCRYPTION=ssl
3)Mailtrap
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=secret_login
MAIL_PASSWORD=secret_pass
MAIL_ENCRYPTION=null
Tested like this - uncommented each section one by one and ran the tests. For example:
class MailRuTest extends TestCase
{
protected $mailer;
protected $mail_host = 'smtp.mail.ru';
protected $mail_port = 465;
protected $mail_username = '{secret_login}@mail.ru';
protected $mail_password = '{secret_pass}';
protected $mail_encryption = 'tls';
protected $msg_from = '[email protected]';
protected $msg_author = 'author_name';
protected $msg_subject = 'Message From to car sharing system - system_name';
protected $msg_to = '[email protected]';
public function setUp()
{
parent::setUp();
$this->mailer = $this->app->make(MailerInterface::class);
}
public function testSend()
{
$this->assertTrue(true);
$this->mailer->raw('Hi, welcome user! ' . date('Y-m-d H:s') . ' - mail_service_name', function ($message) {
$message->to($this->msg_to)
->from($this->msg_from, $this->msg_author)
->subject($this->msg_subject);
});
}
public function testAuth()
{
try{
$transport = new Swift_SmtpTransport($this->mail_host, $this->mail_port, $this->mail_encryption);
$transport->setUsername($this->mail_username);
$transport->setPassword($this->mail_password);
$mailer = new Swift_Mailer($transport);
$mailer->getTransport()->start();
// $this->expectOutputString('Good mailtrap auth');
$this->assertTrue(true);
} catch (Swift_TransportException $e) {
fwrite(STDERR, print_r($this->mail_host. ': '.$e->getMessage() . ' - ' . $this->mail_host, TRUE));
return $e->getMessage();
} catch (\Exception $e) {
fwrite(STDERR, print_r($this->mail_host. ': '.$e->getMessage() . ' - ' . $this->mail_host, TRUE));
return $e->getMessage();
}
$this->assertTrue(true);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question