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.
Build Tests
Code Quality
Tested on Magento 2.4.9
Recent Test History
Each release is tested against the latest Magento version at that time.
Top Contributors
View LeaderboardLooking for Contributors
Dependency injection compilation fails. Your contribution could help the entire Magento community!
Share This Module's Status
README
Loaded from GitHubWebqam 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.