diff --git a/Application/Controller/Admin/SmtpChecker.php b/Application/Controller/Admin/SmtpChecker.php new file mode 100644 index 0000000..387a8ca --- /dev/null +++ b/Application/Controller/Admin/SmtpChecker.php @@ -0,0 +1,110 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\SmtpChecker\Application\Controller\Admin; + +use Assert\Assert; +use Assert\InvalidArgumentException; +use Net_SMTP; +use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController; +use OxidEsales\Eshop\Application\Model\Shop; +use OxidEsales\Eshop\Core\Registry; +use PEAR; + +class SmtpChecker extends AdminDetailsController +{ + protected bool $debug = true; + + protected string $host; + + protected Net_SMTP $smtp; + + public function __construct() + { + parent::__construct(); + + /** @var Shop $activeShop */ + $activeShop = Registry::getConfig()->getActiveShop(); + + $this->host = Registry::getRequest()->getRequestEscapedParameter('') ?? $activeShop->getFieldData('oxsmtp'); + + $this->checkDataAreSet(); + $this->hostIsAvailable(); + +/* + //$host = 'cloud1-vm279.de-nserver.de:587'; + $from = 'mail@ds.data-develop.de'; + $rcpt = array('test@ds.data-develop.de', 'test@daniel-seifert.com', 'recipient2@example.com'); + //$rcpt = array('test@ds.data-develop.de'); + $rcpt = array('test@daniel-seifert.com'); + $subj = "Subject: Test Message\n"; + $body = "Body Line 1\nBody Line 2"; + + if ( PEAR::isError( $e = $smtp->connect())) { + dumpvar(__METHOD__.__LINE__.PHP_EOL); + die($e->getMessage() . "\n"); + } + + if ( PEAR::isError( $smtp->mailFrom( $from))) { + die("Unable to set sender to $from\n"); + } + + foreach ($rcpt as $to) { + dumpvar($to.PHP_EOL); + if ( PEAR::isError( $res = $smtp->rcptTo( $to))) { + die("Unable to add recipient $to: " . $res->getMessage() . "\n"); + } + } + + /* Set the body of the message. */ +/* + if ( PEAR::isError( $res = $smtp->data( $subj . "\r\n" . $body))) { + dumpvar($res->getMessage()); + die("Unable to send data\n"); + } + + /* Disconnect from the SMTP server. */ +/* + $smtp->disconnect(); + */ + } + + protected function checkDataAreSet() + { + } + + /** + * @throws InvalidArgumentException + * @return void + */ + protected function hostIsAvailable() + { + $this->host = 'test.example.dev'; + Assert::that(( $this->smtp = new Net_SMTP( $this->host ) ))->true('Unable to instantiate SMTP object'); + $this->smtp->setDebug($this->debug); + } + + protected function foo() + { + PEAR::isError( $e = $this->smtp->connect()); + dumpvar(get_class($e)); + die(); + Assert::that(PEAR::isError( $e = $this->smtp->connect()))->false($e->getMessage()); + { + dumpvar(__METHOD__.__LINE__.PHP_EOL); + die($e->getMessage() . "\n"); + } + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index f01f63b..c345178 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "require": { "php": ">=7.3", "oxid-esales/oxideshop-ce": "6.8 - 6.14", - "pear/net_smtp": "^1.11" + "pear/net_smtp": "^1.11", + "beberlei/assert": "^3.3" }, "require-dev": { "php": "^7.4", @@ -50,7 +51,7 @@ }, "autoload": { "psr-4": { - "D3\\SMTPChecker\\": "../../../source/modules/d3/smtpchecker" + "D3\\SmtpChecker\\": "../../../source/modules/d3/smtpchecker" } }, "scripts": { diff --git a/menu.xml b/menu.xml new file mode 100644 index 0000000..dc14f59 --- /dev/null +++ b/menu.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/metadata.php b/metadata.php index c01401a..c1cbf39 100644 --- a/metadata.php +++ b/metadata.php @@ -13,6 +13,8 @@ declare(strict_types=1); +use D3\SmtpChecker\Application\Controller\Admin\SmtpChecker; + $sMetadataVersion = '2.1'; $sModuleId = 'd3smtpchecker'; @@ -34,7 +36,7 @@ $aModule = [ 'email' => 'support@shopmodule.com', 'url' => 'https://www.oxidmodule.com/', 'controllers' => [ -// 'd3ControllerAlias' => D3\ThisModule\Application\Controller\Admin\d3Controller::class, + 'd3smtpchecker' => SmtpChecker::class, ], 'extend' => [ // \OxidEsales\Eshop\Core\ShopControl::class => \D3\ThisModule\Modules\Core\ShopControl_MyModule::class