taitava / swiftmailer-imapsentfolder
一个 SwiftMailer 插件,将所有已发送的消息副本存储在 IMAP 电子邮件服务器的文件夹中。
1.0.2
2019-04-12 09:34 UTC
Requires
- ext-imap: *
- swiftmailer/swiftmailer: >=5
This package is auto-updated.
Last update: 2024-09-12 22:16:06 UTC
README
这是一个 SwiftMailer 插件,将所有*已发送的电子邮件消息存储到 IMAP 服务器(或服务器)上。
*) 可选地,您可以使用回调函数创建一个自定义过滤器,以防止在需要时保存消息。
此功能仅适用于 IMAP 服务器,不支持任何其他协议! 不论最初用于发送消息的协议是什么。
需求
- SwiftMailer 5 或 6
- PHP imap 扩展
安装
composer require taitava/swiftmailer-imapsentfolder
用法
use \Taitava\ImapSentFolder\ImapSentFolderPlugin; $mailer = Swift_Mailer::newInstance(); // Define mailboxes like this: $mailboxes = [ 'email.address@somedomain.tld' => [ 'host' => 'imap.somedomain.tld', 'port' => 993, 'username' => 'email.address', 'password' => 'verysecretdonotsharepubliclyintheinternet', 'sent_folder' => 'Sent', ], 'default' => [ 'host' => 'imap.somedomain.tld', 'port' => 993, 'username' => 'other.account', 'password' => 'verysecretdonotsharepubliclyintheinternet', 'sent_folder' => 'Sent', ], ]; $plugin = new ImapSentFolderPlugin($mailboxes); $mailer->registerPlugin($plugin);
插件将自动通过检查发送的电子邮件消息中的 'From' 字段来选择正确的邮箱。如果未在 $mailboxes
数组中找到电子邮件地址,则插件将使用具有键 'default' 的定义的邮箱。如果可能的话,您应该始终定义一个默认邮箱,以防邮件是从未预见的电子邮件地址发送的!
控制要保存的内容和不保存的内容
您可以定义一个自定义回调函数,该函数将在保存已发送的电子邮件消息之前被调用。
use \Taitava\ImapSentFolder\ImapSentFolderPlugin; $plugin = new ImapSentFolderPlugin($mailboxes); $plugin->setCallBeforeSaving(function (Swift_Mime_Message $email_message){ // ... Inspect the $email_message instance ... // ... Decide not to save this message ... return false; // ... Decide to accept saving the message ... return true; // ... If you do not write a 'return' statement or if you return null, saving is also accepted ... return; });
未来
欢迎提出想法(以及拉取请求) :)。 目前没有大的计划,我认为这个插件相当完整。但如果有任何问题出现,我会尝试修复。
作者
哦,这只是我一个人。太懒了,不想写我的名字。 :)
许可证
MIT