定制 taitava/swiftmailer-imapsentfolder 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

taitava/swiftmailer-imapsentfolder

Composer 安装命令:

composer require taitava/swiftmailer-imapsentfolder

包简介

A SwiftMailer plugin that stores a copy of all sent messages to a folder on an IMAP email server.

README 文档

README

This is a plugin for SwiftMailer that stores all* sent email messages to an IMAP server (or servers).

*) Optionally you can use a callback function to create a custom filter that can prevent saving messages if needed.

This feature only works with IMAP servers, any other protocols are not supported! It does not matter, which protocol was originally used to send the message.

Requirements

  • SwiftMailer 5 or 6
  • PHP imap extension

Installation

composer require taitava/swiftmailer-imapsentfolder

Usage

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);

The plugin will automatically pick the correct mailbox by inspecting the 'From' field from the email message that was sent. If the email address is not found from the $mailboxes array, the plugin will use the mailbox defined with the key 'default'. You should always define a default mailbox if its possible that mail is sent from unforeseen email addresses!

Control what gets saved and what not

You can define a custom callback function that will be called right before saving a sent email message.

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;
});

Future

Ideas (and pull requests) are welcome :). No big plans at the moment, I'm considering this plugin quite complete. But will try to fix issues if any arise.

Author

Oh, it's just me. Too lazy to write my name. :)

License

MIT

统计信息

  • 总下载量: 19
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固