Skip to content

Commit 8ef4757

Browse files
committed
Консольная команда проверки отправки почты
1 parent afc5129 commit 8ef4757

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
namespace Prokl\BitrixOrdinaryToolsBundle\Commands;
3+
4+
use CSiteCheckerTest;
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
9+
/**
10+
* Class EmailsCanBeSendCommand
11+
*
12+
* @package Prokl\BitrixOrdinaryToolsBundle
13+
*
14+
* @since 27.08.2021
15+
*/
16+
class EmailsCanBeSendCommand extends Command
17+
{
18+
/**
19+
* @inheritDoc
20+
*/
21+
public function configure()
22+
{
23+
$this->setName('bitrix:check-send-email')
24+
->setDescription('Check mail sending');
25+
}
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
public function execute(InputInterface $input, OutputInterface $output): int
31+
{
32+
$output->writeln('Testing capability of email sending started...');
33+
34+
$siteChecker = new CSiteCheckerTest;
35+
if (!$siteChecker->check_mail()) {
36+
$output->writeln('Sending email failed.');
37+
}
38+
39+
if (!$siteChecker->check_mail_big()) {
40+
$output->writeln('Sending big email failed.');
41+
}
42+
43+
$result = $this->runCheck($output);
44+
if ($result) {
45+
$output->writeln('Testing sending of email finished successfully.');
46+
} else {
47+
$output->writeln('Testing sending of email failed.');
48+
}
49+
50+
return 0;
51+
}
52+
53+
/**
54+
* @param OutputInterface $output
55+
*
56+
* @return bool
57+
*/
58+
private function runCheck(OutputInterface $output) : bool
59+
{
60+
$defaultMailResult = false;
61+
$largeMailResult = false;
62+
if (function_exists('mail')) {
63+
$emailTo = 'hosting_test@bitrixsoft.com';
64+
$subject = 'testing mail server';
65+
$message = 'testing mail server';
66+
$headers = 'From: webmaster@example.com' . "\r\n" .
67+
'Reply-To: webmaster@example.com' . "\r\n" .
68+
'X-Mailer: PHP/' . phpversion();
69+
70+
$defaultMailResult = mail($emailTo, $subject, $message, $headers);
71+
if (!$defaultMailResult) {
72+
$output->writeln('Mail server not configured.');
73+
}
74+
75+
$largeMailResult = (new CSiteCheckerTest)->check_mail_big();
76+
if (!$largeMailResult) {
77+
$output->writeln('Sending big email failed');
78+
}
79+
}
80+
81+
return $defaultMailResult && $largeMailResult;
82+
}
83+
}

Resources/config/console.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
####################
2+
# Консольные команды
3+
####################
4+
5+
services:
6+
# конфигурация по умолчанию в *этом* файле
7+
_defaults:
8+
autowire: true
9+
autoconfigure: true
10+
public: true
11+
12+
13+
# Проверка - отправляется email или нет.
14+
Prokl\BitrixOrdinaryToolsBundle\Commands\EmailsCanBeSendCommand:
15+
tags:
16+
- { name: console.command, command: bitrix:check-send-email }

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"symfony/dependency-injection": "^4.4 || ^5.0",
2525
"symfony/http-kernel": "4.4 || ^5.0",
2626
"symfony/config": "4.4 || ^5.0",
27+
"symfony/console": "4.4 || ^5.0",
2728
"intervention/image": "^2.5",
2829
"monolog/monolog": "~1 || ~2",
2930
"league/html-to-markdown": "^5.0"

readme.MD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,11 @@ parameters:
240240
```
241241
242242
Если такой переменной нет, то прогревается только главная (`/`) страница.
243+
244+
## Консольные команды
245+
246+
1) Проверка - отправляется электронная почта или нет
247+
248+
```bash
249+
php bin/console bitrix:check-send-email
250+
```

0 commit comments

Comments
 (0)