0

I'm trying to send a message by email after an order is placed with observer.

The following is the code in my Observer,

    <?php

namespace TestModule\OrderComment\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Mail\Template\TransportBuilder;

use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Translate\Inline\StateInterface;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class SalesOrderPlaceAfterObserver implements ObserverInterface
{
    const SENDER_EMAIL='trans_email/ident_general/email';
    /**
     * Email Template
     */
    const EMAIL_TEMPLATE='orderupdate/email/email_template';

    public function __construct(StoreManagerInterface $smi,
                                TransportBuilder $tb,
                                StateInterface $si,
                                ScopeConfigInterface $scopeConfig
    )
    {
        $this->storeManager=$smi;
        $this->transportBuilder=$tb;
        $this->inlineTranslation=$si;
        $this->scopeConfig = $scopeConfig;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {


        $cname = "customer name";
        $templateOptions = array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->storeManager->getStore()->getId());
        $templateVars = array(
            'store' => $this->storeManager->getStore(),
            'customer_name' => $cname,
            'message'   => 'test message'
        );
        $from = array('email' => "test@example.com", 'name' => 'AnyName');
        $this->inlineTranslation->suspend();
        $to = array('myemail@example.com');
        $transport = $this->transportBuilder->setTemplateIdentifier('myemail_email_template')
            ->setTemplateOptions($templateOptions)
            ->setTemplateVars($templateVars)
            ->setFrom($from)
            ->addTo($to)
            ->getTransport();
        $transport->sendMessage();
        $this->inlineTranslation->resume();
    }
}

But I'm getting this error when placing orders.

STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:3D0D0000, 17.43559:0000000094000000000000000200000000000000, 20.52176:140F0E85180010100A008883, 20.50032:140F0E858817101003000B37, 0.35180:B6000000, 255.23226:0A000137, 255.27962:0A000000, 255.27962:0E000000, 255.31418:C0000000, 16.55847:8E000000, 17.43559:0000000068010000000000000200000000000000, 20.52176:140F0E8518001010CF000000, 20.50032:140F0E8588171010D4000000, 0.35180:0A00DF82, 255.23226:D9000000, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:E3000000, 4.21921:DC040000, 255.27962:FA000000, 255.1494:0A005A85, 0.37692:02000100, 0.37948:02000100, 5.33852:00000000534D545000000100, 4.56248:DC040000, 7.40748:010000000000010B32343A48, 7.57132:00000000000000003A323931, 1.63016:32000000, 4.39640:DC040000, 8.45434:9D79BF8C8650E940A0E63AF29BA7E5514300E702, 5.10786:0000000031352E32302E313239342E3032343A4845"

I have tried this both on my local maching and on a live server which I know that php email function is working properly.

Did I missing anything?

0

The issue seems to be at your server end. Send As Denied Exception might occur if the Clutter feature is enabled for the user but the Clutter folder is missing in the user’s mailbox. You can refer to these links if it helps:

Send As Denied Exception

How to resolve it

  • But PHP mail() function is working good. It's just Magentos API has problem with sending emails. – Magento Learner Nov 8 '18 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.