codeminds/mailmanager

在一个中央位置管理所有发出的邮件。在一个yaml文件中配置所有邮件,并通过一个开关禁用或重定向所有邮件进行调试。将邮件内容输出到文件,以便更快地进行调试。

安装: 7

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:typo3-cms-extension

1.0.0 2019-12-06 18:04 UTC

This package is auto-updated.

Last update: 2024-09-07 04:19:30 UTC


README

1. 特性

  • 通过在一个单一的yaml配置文件中配置它们,在一个中央位置管理所有发出的邮件。
  • 使用一个开关禁用或重定向所有邮件进行调试。因此,您可以在开发期间提前定义正确的实时电子邮件地址,而不必担心在上线时忘记切换它们。
  • 将邮件内容输出到可访问的html文件,以便快速调试,而无需将您的收件箱填满。

2. 使用方法

1) 安装

使用Composer安装扩展:composer require codeminds/mailmanager

2) 最小配置

  1. 创建一个用于邮件配置的yaml文件(例如,在您的站点包扩展中,在Configuration/Yaml/Mails.yaml内)
  2. 通过TypoScript定义您的yaml文件的位置:plugin.tx_mailmanager.settings.configurationFilePath = EXT:your_site_package/Configuration/Yaml/Mails.yaml
  3. 在您的yaml文件(EXT:your_site_package/Configuration/Yaml/Mails.yaml)中设置您的第一个邮件配置
configurations:
  -
    identifier: 'MyIdentifier'
    isActive: true
    senderEmailAddress: 'sender@company.com'
    senderName: 'My sender'
    recipients:
      -
        emailAddress: 'recipient@company.com'
        name: 'My recipient'
    subject: 'My subject'
    templatePathAndFileName: 'EXT:your_site_package/Resources/Private/Templates/Mails/YourIdentifier.html'
    partialRootPaths: []
    layoutRootPaths: []
debug:
  disableDelivery: false
  enableRerouting: false
  reroutingEmailAddress: 'debug@company.com'
  reroutingName: 'Debug'
  enableDebugOutputToFiles: false
  1. 定义您的模板(EXT:your_site_package/Resources/Private/Templates/Mails/YourIdentifier.html
<p>Dear customer,</p>
<p>this is a hello {variable} example mail</p>
<p>Cheers</p>
  1. 使用提供的MailService发送您的邮件
use TYPO3\CMS\Extbase\Annotation\Inject;

/**
 * @Inject
 * @var Codeminds\MailManager\Service\MailService
 */
protected $mailService = null;

.
.
.

$variables = array('variable' => 'world');
$this->mailService->sendMail('MyIdentifier', $variables);

3) 额外配置(可选)

a) 在配置中使用变量

您可以在yaml配置中使用变量,例如,动态设置收件人。通过使用花括号引用变量:{variableName}。也可以引用嵌套变量:{variable.nested.variableName}。示例

configurations:
  -
    identifier: 'MyIdentifier'
    isActive: true
    senderEmailAddress: 'sender@company.com'
    senderName: 'My sender'
    recipients:
      -
        emailAddress: '{variableName}'
.
.
.

b) 与TYPO3表单一起使用

  1. 包含扩展的静态TypoScript。
  2. 现在您可以在表单模块中添加两个新的完成器:通过MailManager提交电子邮件和通过MailManager发送给您的电子邮件
  3. 在完成器中,您必须定义相应邮件配置的标识符
  4. 可选地,您可以设置收件人或发件人为来自表单的动态设置的值(邮件配置必须相应地定义,通过设置{emailAddress}{name}
  5. 定义表单扩展的模板和部分(或使用您自己的)。在您的yaml邮件配置中
    templatePathAndFileName: 'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/Html.html'
    partialRootPaths: ['EXT:form/Resources/Private/Frontend/Partials']

c) 调试

在您的yaml文件中的debug下使用自解释的选项。如果enableDebugOutputToFiles处于开启状态,文件将放置于/typo3temp/mails/MyIdentifier.html,以便通过浏览器快速访问。

d) 完整配置和附件

您还可以配置cc、bcc、回复地址和附件。请参阅此配置,其中使用了所有可能选项

configurations:
  -
    identifier: 'MyIdentifier'
    isActive: true
    senderEmailAddress: 'sender@company.com'
    senderName: 'My sender'
    recipients:
      -
        emailAddress: 'recipient@company.com'
        name: 'My recipient'
    cc:
      -
        emailAddress: 'cc@company.com'
        name: 'My cc recipient'
    bcc:
      -
        emailAddress: 'bcc@company.com'
        name: 'My bcc recipient'
    replyTo:
      -
        emailAddress: 'replyto@company.com'
        name: 'My replyto name'
    subject: 'My subject'
    attachments: ['EXT:your_site_package/Resources/Private/Pds/attachment.pdf']
    templatePathAndFileName: 'EXT:your_site_package/Resources/Private/Templates/Mails/YourIdentifier.html'
    partialRootPaths: []
    layoutRootPaths: []
debug:
  disableDelivery: false
  enableRerouting: false
  reroutingEmailAddress: 'debug@company.com'
  reroutingName: 'Debug'
  enableDebugOutputToFiles: false

以编程方式附加文件

$pathAttachments[] = 'EXT:your_site_package/Resources/Private/Pds/attachment.pdf';
$file = $myFileReference->getOriginalResource();
$swiftAttachments[] = Swift_Attachment::newInstance($file->getContents(), $file->getName(), $file->getMimeType());
$this->mailService->sendMail('MyIdentifier', $variables, $pathAttachments, $swiftAttachments);