The Home for Magento 2 Excellence

Quality-tested Magento 2 modules. Explore. Evaluate. Elevate. #magento2

1090 Modules
617 Ready
473 Need Help
🏆 Leaderboard
Stable v1.2.2

Webqam Email Attachment for Magento 2

webqam/magento2-module-emailattachment

Adds attachment support to Magento's mail TransportBuilder and enables attaching files to sales order emails via observers, for sending invoices or documents with transactional emails.

7,746
Downloads
Below average
5
GitHub Stars
Below average
10mo ago
Last Release
0
Open Issues
Build Issues
2/3 checks passed

Build Tests

Composer Install
DI Compile
Templates

Code Quality

CS Coding Standard
15 warnings
PHPStan Failed

Tested on Magento 2.4.9

Recent Test History

Each release is tested against the latest Magento version at that time.

v1.2.2 on Magento 2.4.9
Jun 2, 2026

Looking for Contributors

Dependency injection compilation fails. Your contribution could help the entire Magento community!

Contribute

Share This Module's Status

Webqam Email Attachment for Magento 2 Magento compatibility status badge

README

Loaded from GitHub

Webqam Email Attachment module

Installation

composer require webqam/magento2-module-emailattachment
bin/magento setup:upgrade

Usage

Add attachment on an email

This module add a method to Magento\Framework\Mail\Template\TransportBuilder (using Preference). You can use method addAttachment of TransportBuilder class.

Attachment for sales order email

use email_order_set_template_vars_before observer

use Magento\Framework\DataObject;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Webqam\EmailAttachment\Model\Order\Email\Container\AttachmentIdentityInterface;

class OrderSetTemplateVarsBefore implements ObserverInterface
{
    /**
     * Execute observer
     *
     * @param Observer $observer
     * @return void
     */
    public function execute(
        Observer $observer
    ) {
        /** @var DataObject $transportObject */
        $transportObject = $observer->getDataByKey('transportObject');
        $attachments = $transportObject->getDataByKey(
            AttachmentIdentityInterface::KEY_TEMPLATE_VARS_EMAIL_ATTACHMENTS_DATA
        );

        $attachment = [
            AttachmentIdentityInterface::KEY_ATTACHMENT_CONTENT   => 'content',
            AttachmentIdentityInterface::KEY_ATTACHMENT_FILE_NAME => 'filename.pdf',
            AttachmentIdentityInterface::KEY_ATTACHMENT_FILE_TYPE => 'pdf'
        ];

        if ($attachments && is_array($attachments)) {
            $attachments[] = $attachment;
            $transportObject->setData(
                AttachmentIdentityInterface::KEY_TEMPLATE_VARS_EMAIL_ATTACHMENTS_DATA,
                $attachments
            );
        } else {
            $transportObject->setData(AttachmentIdentityInterface::KEY_TEMPLATE_VARS_EMAIL_ATTACHMENTS_DATA, [
                $attachment
            ]);
        }
    }
}

This content is fetched directly from the module's GitHub repository. We are not the authors of this content and take no responsibility for its accuracy, completeness, or any consequences arising from its use.