Giter Club home page Giter Club logo

outbox's Introduction

ATK4 Outbox

Most web applications will need to communicate with the user. Following the task-centric approach, this add-on for ATK implements various components to help communicate with the user.

The basic idea is to avoid errors and provide only one way to use the component.

How to install

composer require atk4/outbox

How to use with Atk4/Ui

Add the lines below after calling $app->initLayout()

$app->add([Outbox::class, [
    'mailer' => new Sendmail(),
    'model' => new Mail($this->db),
]]);

After that you can call from any view $this->getApp()->getOutbox()

How to use without Atk4/Ui

Add the code below :

$outbox = new Outbox([
    'mailer' => new Sendmail(),
    'model' => new Mail($this->db),
]);

Due to missing App, init is not called so you have to do it you have to run it

$outbox->invokeInit(); 

Mailer (PHMailer)

  • Sendmail
  • Gmail
    • can be customized using Atk4 direct injection :
      • username
      • password
  • Smtp
    • can be customized using Atk4 direct injection :
      • debug = PHPMailer::DEBUG_OFF;
      • auth = false
      • host = 'localhost';
      • port = 587;
      • secure = PHPMailer::ENCRYPTION_*
      • username
      • password

Extend Mailer

Whatever your needs are you must respect only the contract provided by the MailerInterface interface. So, any Traditional SMTP or API SMTP can be added only by create a new class and define the method : send(Mail $mail): MailResponse, add to Outbox during initialization and use it.

If you create a new Mailer, feel free to open a PR.

How to use it

// request an new email from outbox  
$mail = $outbox->new();

// use an already saved mail template
$mail->withTemplateIdentifier('template_test');

// replace token with data
$mail->replaceContent('token', 'Agile Toolkit');

// Add a custom address as "to"
$mail->ref('to')->createEntity()->save([
    'email' => '[email protected]',
    'name' => 'destination',
]);

// send the mail and check the response 
$response = $outbox->send($mail);

TODO

  • Store the token present in a template, inside a field (at the moment, there is only a draft)
  • Add more helpers to the Mail template or create a controller to manipulate it and leave it simpler as a descriptor
  • Add a wysiwyg editor to edit individual templates (UI)
  • Add resend system for failed messages
  • Send SMS
  • If you have more ideas, feel free to open an issue

outbox's People

Contributors

abbadon1334 avatar darkside666 avatar romaninsh avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

abbadon1334

outbox's Issues

Start dev. Track progress

  • Models
  • Mailer
  • Implement Gmail as Mailer
  • Outbox must be used with and without App
  • Queue Sending
  • send -> Single Response
  • send -> Multiple Response ( some API return multiple response)
  • send -> Response -> Multiple email errors
  • WebHooks - some API, give a partial OK response, for Validated Mail message, but after that call back a url with response of sending actions

I see two ways of sending emails :

/** @var Outbox $outbox */
$outbox = $this->getApp()->getOutbox();

$mail = $outbox->new()
    ->withTemplateIdentifier('test')
    ->replaceContent('test','testing')
;

$outbox->send($mail);
/** @var Outbox $outbox */
$outbox = $app->getOutbox();

$outbox->callableSend(static function(Mail $mail) use ($user_model) {

    $mail->withTemplateIdentifier('test')
        ->replaceContent('test','testing')
        ->replaceContent( $user_model, 'user');

    return $mail;
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.