0

Is there any Event or Observer to Add BCC in Shipment Email Programmatically

Task Is Shipment Mail Send 2 Person 1st is customer and 2nd is dynamic email

Please Provide me Suggestion How To Add Programmatically BCC in Shipment Email ?

How Can I Do This ??

1

You can add it in configuration

  • On the Admin Panel, Stores > Settings > Configuration.
  • On the left panel, under Sales tab, click on Sales Emails subtab.
  • Open the shipment section
  • Add email or comma separated email in 'Send Shipment Email Copy To'

If you want to customise this beyond configuration you are changing this:

https://github.com/magento/magento2/blob/2.3/app/code/Magento/Sales/Model/Order/Email/Container/ShipmentIdentity.php#L40-L47

So observer or plugin (Interceptor) - not event.

https://devdocs.magento.com/guides/v2.3/extension-dev-guide/plugins.html

https://devdocs.magento.com/guides/v2.3/extension-dev-guide/events-and-observers.html

Here is a suggestion on how to go Plugin Route

Xigen\Override

etc/di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Model\Order\Email\Container\ShipmentIdentity">
        <plugin disabled="false" name="Xigen_Override_Plugin_Magento_Sales_Model_Order_Email_Container_ShipmentIdentity" sortOrder="10" type="Xigen\Override\Plugin\Magento\Sales\Model\Order\Email\Container\ShipmentIdentity"/>
    </type>
</config>

Plugin/Magento/Sales/Model/Order/Email/Container/ShipmentIdentity.php

namespace Xigen\Override\Plugin\Magento\Sales\Model\Order\Email\Container;

class ShipmentIdentity
{

    public function afterGetEmailCopyTo(
        \Magento\Sales\Model\Order\Email\Container\ShipmentIdentity $subject,
        $result
    ) {
        //Your plugin code
        return $result;
    }
}
  • i want to add bcc Programmatically – Rk Rathod Jul 8 at 12:54
  • Try plugin route – Dominic Xigen Jul 8 at 12:59
  • please explain how to use plugin route – Rk Rathod Jul 8 at 13:00
  • I have updated answer – Dominic Xigen Jul 8 at 13:04
  • i will check and update soon – Rk Rathod Jul 8 at 13:05
1

you can use this event "email_invoice_set_template_vars_before" and you can also find more events here :

https://www.magestore.com/magento-2-tutorial/use-event-magento-2

  • please explain briefly and i want to add bcc in shipment email – Rk Rathod Jul 8 at 12:55
  • as per my task shipment mail send 2 person 1st is customer and 2nd is dynamic email so how can i do this ?? check my updated answer – Rk Rathod Jul 9 at 7:28
  • 1+ for response – Rk Rathod Jul 9 at 8:06
1

You can managed to work it by following code:

Step 1: Create a module with name Vendor_Module and do the following changes.

Step 2: create di.xml under

app/code/Vendor/Module/etc/di.xml

with content:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Model\Order\Email\Sender\ShipmentSender" type="Vendor\Module\Model\Order\Email\Sender\ShipmentSender" />
</config>

Step 3: Create SenderBuilder.php under

app/code/Vendor/Module/Model/Order/Email/Sender/ShipmentSender.php

with content:

<?php

namespace Vendor\Module\Model\Order\Email\Sender;


class ShipmentSender extends \Magento\Sales\Model\Order\Email\Sender\ShipmentSender
{

    public function send(Shipment $shipment, $forceSyncMode = false)
    {
        //do your logic
    }
}

And then run required commands bin/magento setup:upgrade bin/magento setup:di:compile bin/magento setup:static-content:deploy bin/magento cache:clean. You can modify the codes according to your requirement.

Note: Above codes are not Tested but it should work.

  • i will check and update soon – Rk Rathod Jul 8 at 13:17
  • as per my task shipment mail send 2 person 1st is customer and 2nd is dynamic email so how can i do this ?? check my updated answer – Rk Rathod Jul 9 at 7:28
  • 1+ for response – Rk Rathod Jul 9 at 8:06

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.