shockwavemk / magento2-module-mail
扩展 Magento2 邮件功能的基模块
This package is not auto-updated.
Last update: 2024-09-14 19:14:45 UTC
README
本模块增强了 Magento 2 发送事务性邮件的能力。在普通的 Magento 2 安装中,既无法跟踪和管理 Magento 2 系统发送的事务性邮件,也无法在本地或备份服务提供商处存储邮件。
此邮件模块区分了邮件处理的各个部分
-
一个邮件传输系统,负责将出站邮件传输到邮件服务提供商,并检索邮件实体的返回元数据。
-
一个邮件存储系统,负责在文件系统中存储出站邮件及其元数据。
所实现的传输系统和存储系统都包含一个可配置的 Magento 2 基类和一个用于动态加载插件类的第二个类,该类执行实际的传输。因此,可以保留此邮件模块的丰富基本功能,并通过供应商特定的功能进行增强。
安装
将模块添加到您的 composer 文件中。
{ "require": { "shockwavemk/magento2-module-mail": "dev-master" } }
使用 composer 安装模块。
composer update
成功后,通过 bin/magento 控制台安装模块。
bin/magento cache:clean bin/magento module:enable Shockwavemk_Mail_Base bin/magento setup:upgrade
功能
通过可配置的插件发送邮件
传输和存储配置可以通过商店配置轻松完成。在此处可以选择已安装的传输和存储插件。
支持的供应商(目前)
传输
- 任何 SMTP 服务器
- Mailgun
存储
- 本地服务器存储
- Dropbox
将邮件元数据存储在数据库中
将邮件数据作为 json 文件存储
每个由 Magento 2 发送的邮件都作为单独的 json 文件存储。
此外,每个邮件的渲染版本都存储为 .hmtl 文件。这减少了审查时的加载时间,并使外部存储系统能够预览存储的内容。
默认存储将所有由 Magento2 发送的文件存储在所谓的“spool”文件夹中。邮件数据将保留在此本地服务器路径上,直到删除或移动。
安装存储插件后,cronjob 将自动负责将所有存储的邮件移动到您的安全外部存储位置。即使您的服务器重新安装或您需要清理 Magento 安装:与客户的对话也是安全的。
通过事务性邮件审查增强管理员客户管理
客户管理通过额外的菜单标签得到增强。
在主要管理员菜单中选择客户
营销 - 用户内容 - 标签通过一个额外的菜单点得到增强。在此新部分中,您可以审查和重新发送 Magento2 系统发送的所有(访客和客户)邮件。
重新发送事务性邮件。重新计算或重新发送存储的邮件数据
此扩展跟踪从商店发送的每一封电子邮件。对于每一封邮件,都可以触发重新发送。
附件处理和发送文件的存储
基本邮件模块支持附件发送。Magento2 不支持原生文件附件处理,因此您需要添加一些自己的代码。
要添加文件系统中的文件,您需要将您的邮件发送策略更改为“异步”。
您必须修改/覆盖 EmailSenderHandler 类。
/** * @param \Magento\Sales\Model\Order\Email\Sender $emailSender * @param \Magento\Sales\Model\ResourceModel\EntityAbstract $entityResource * @param \Magento\Sales\Model\ResourceModel\Collection\AbstractCollection $entityCollection * @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig * @param Config $documentConfig * @param ObjectManagerInterface $objectManager */ public function __construct( \Magento\Sales\Model\Order\Email\Sender $emailSender, \Magento\Sales\Model\ResourceModel\EntityAbstract $entityResource, \Magento\Sales\Model\ResourceModel\Collection\AbstractCollection $entityCollection, \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig, ObjectManagerInterface $objectManager ) { parent::__construct($emailSender, $entityResource, $entityCollection, $globalConfig); $this->objectManager = $objectManager; $this->documentConfig = $documentConfig; // Dynamic typed build a collection for attachments for later usage // Should be extended from \Magento\Framework\Data\Collection $this->attachmentCollection = $this->objectManager->get( 'Shockwavemk\Mail\Base\Model\Mail\AttachmentCollectionInterface' ); } /** * Handles asynchronous email sending * * @return void * @throws \RuntimeException * @throws \Exception */ public function sendEmails() { /** @var \Magento\Sales\Model\AbstractModel $item */ foreach ($this->entityCollection->getItems() as $item) { // add this code // Create a new attachment if (!is_null($attachmentFilePath)) { /** @var \Shockwavemk\Mail\Base\Model\Mail\AttachmentInterface|\Magento\Framework\DataObject $attachment */ $attachment = $this->objectManager ->create('Shockwavemk\Mail\Base\Model\Mail\AttachmentInterface'); // Do not transfer binary data to mail entity at this point: The mailer can handle file reading on its own $attachment->setFilePath($attachmentFilePath); // Add attachment to attachment collection // Let the mailer later decide how to handle them $this->attachmentCollection->addItem($attachment); } } }