Giter VIP home page Giter VIP logo

cakephp-email-queue's Introduction

CakePHP Email Queue plugin

This plugin provides an interface for creating emails on the fly and store them in a queue to be processed later by an offline worker using a cakephp shell command.

It also contains a handy shell for previewing queued emails, a very handy tool for modifying email templates and watching the result.

Requirements

  • CakePHP 4.x

Installation

composer require lorenzo/cakephp-email-queue

The plugin uses Debug email transport, so make sure your email config contain it:

'EmailTransport' => [
        'Debug' => [
            'className' => 'Debug'
        ],
]

Enable plugin

bin/cake plugin load EmailQueue

Load required database table

In order to use this plugin, you need to create a database table. Required SQL is located at

# config/Schema/email_queue.sql

Just load it into your database. You are free to change the file to use an integer primary key instead of UUIDs.

Or run migrations command:

bin/cake migrations migrate --plugin EmailQueue

Usage

Whenever you need to send an email, use the EmailQueue model to create and queue a new one by storing the correct data:

use EmailQueue\EmailQueue;
EmailQueue::enqueue($to, $data, $options);

enqueue method receives 3 arguments:

  • First argument is a string or array of email addresses that will be treated as recipients.
  • Second arguments is an array of view variables to be passed to the email template
  • Third arguments is an array of options, possible options are
  • subject: Email's subject
  • send_at: date time sting representing the time this email should be sent at (in UTC)
  • template: the name of the element to use as template for the email message. (maximum supported length is 100 chars)
  • layout: the name of the layout to be used to wrap email message
  • format: Type of template to use (html, text or both)
  • headers: A key-value list of headers to send in the email
  • theme: The View Theme to find the email templates
  • config: the name of the email config to be used for sending
  • from_name: String with from name. Must be supplied together with from_email.
  • from_email: String with from email. Must be supplied together with from_name.

Previewing emails

It is possible to preview emails that are still in the queue, this is very handy during development to check if the rendered email looks at it should; no need to queue the email again, just make the changes to the template and run the preview again:

# bin/cake EmailQueue.preview

Sending emails

Emails should be sent using bundled Sender command, use -h modifier to read available options

# bin/cake EmailQueue.sender -h

You can configure this command to be run under a cron or any other tool you wish to use.

Contributing

Run the tests

./vendor/bin/phpunit tests/

Check style

./vendor/bin/phpcs ./src ./tests/ --standard=vendor/cakephp/cakephp-codesniffer/CakePHP

cakephp-email-queue's People

Contributors

achepukov avatar ad7six avatar angelxmoreno avatar anhtuank7c avatar ankr avatar f0xx16 avatar henrikjuul avatar ishanvyas22 avatar jippi avatar julianpollmann avatar k1low avatar lorenzo avatar noglitchyo avatar pabloelcolombiano avatar parkmira avatar phantomwatson avatar saeideng avatar stripthis avatar waspinator avatar zledwon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cakephp-email-queue's Issues

Why does the plugin use serialize and not json per default?

Hi there,

thanks for the plugin. This is rather a question. I am experiencing issues using serialize type with Postgres, so I'll shift my implementation to json.

Were there any security concerns or drawback using json? What is the motivation behind using serialize per default?

Upgrade to CakePHP 4.3

This issue addresses deprecation messages introduced in CakePHP 4.3.

Additionally, the fixture management is now handled by migrations.

A pull request will follow to have these deprecation messages solved.

cake 3 : Undefined index: template

Notice : Undefined index: template [ROOT/vendor/lorenzo/cakephp-email-queue/src/Model/Table/EmailQueueTable.php, line 61]

tag: 3.3.1 (compatible with cake 3)

if (strlen($options['template']) > self::MAX_TEMPLATE_LENGTH) {

solved in version 4
tag: 4.0.0 (compatible with cake 4)

if (array_key_exists('template', $options) && strlen($options['template']) > self::MAX_TEMPLATE_LENGTH) {

could you fix and do new tag for cake 3 ?
no base branch for it and I could not open a PR

Using migration

Why you do not use migration instead of using the shema to create the table?

Is this is a better way to do or is it just that migration are not available in the plugins?

send_at is wrong date

If create email in table email_queue in column send_at is sam date as column created.
after send is set column sent to 1 bad column send_at not changed.

Domain name in URLs

Just noticed that I can not use Html Helper or Url Helper with full base links.
The domain, reverts to localhost

Options being ignored

These lines appear to have the effect of "if the specified layout is default, then the specified configName, template, and layout will be ignored when the email is being sent and replaced with values provided in the command line or defined in SenderShell::getOptionParser()".

I'm trying to use this plugin and I'm not able to use any template file or config value other than default while the layout is default.

Can you confirm that this is a bug, or is this the expected behavior?

Regarding reply-to option/functionality.

Hello,

There is no option/functionality to set reply-to. In various company they use one mail id to send mails.
So what basic idea is generally if some one get an email from sender, the concern person i.e receiver can reply to the sender and vice-versa.

Now using this email queue functionality which you have given there is no facility to set reply-to. So how to do this.

Kindly help.

MessageId is required in order to avoid spam

I've just discovered that exchange will consider as spam an email without a messageId.

Is there a reason why you set it to false in SenderShell.php?
Line 122
my proposal is to set it to true (or not set at all to use the default)

                $sent = $email
                    ->setTo($e->email)
                    ->setSubject($e->subject)
                    ->setEmailFormat($e->format)
                    ->addHeaders($headers)
                    ->setViewVars($viewVars)
                    ->setMessageId(true)
                    ->setReturnPath($email->getFrom());

See the results of the recipt

                              X-Spam-Flag: NO
                              
                              X-Spam-Score: -2.512
                              
                              X-Spam-Level:
                              
                              X-Spam-Status: No, score=-2.512 tagged_above=-9999 required=5

               tests=[ALL_TRUSTED=-1, BAYES_00=-1.9, DKIM_SIGNED=0.1,

               DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,

               HTML_MESSAGE=0.001, MIME_HTML_ONLY=0.1, **MISSING_MID=0.497**,

               SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_BLOCKED=0.001]

               autolearn=ham autolearn_force=no

Sent at timezone

Dear Lorenzo.
Why we have to use

'send_at' => new FrozenTime('now', 'UTC'),

instead of

'send_at' => new FrozenTime('now'),

I think we should unified default timezone configured in bootstrap.php

Ver 4.0: seem Mail Queue send separated email to each recipient

Great plugin! I really appreciate your works. Thank you.

I am using CakePHP 4.

When making a test from my app, sending email from person A to person B, both have the same email address (of mine), I received 2 identical emails.

And I notice that the time EmailQueue.sender takes to send 1 email is longer than the time I send the same email template from my App controller action (send directly). When I use this direct approach, I only get 1 email instead of 2.

I think EmailQueue send 2 separate emails. Instead of adding recipient to To, it actually create new email.

Maximum Retry Count

Is there any way to configure the maximum retry count via bootstrap.php or wherever?
I would like to request that this library should have an option to configure the maximum count.

@lorenzo

i18n language translate

Is there a way to set the language using i18n of the email when adding to the queue? Or is the solution to just create language specific templates?

attachments

How can i add attachments to emails that need to be send ?

Thank you

License?

This plugin looks like it will do exactly what I need, but there is no license specified. In order to use it at my work this needs to be made explicit (MIT license ideally).

Preview - Objects used as Array

My Configurations:

$ php --version 
PHP 5.6.29 (cli) (built: Dec  9 2016 07:03:56) 
$ bin/cake --version
3.4.5

While checking preview got these errors:

[Exception: Transport config "Debug" is missing. in [/my/project/path/vendor/cakephp/cakephp/src/Mailer/Email.php, line 1525]

2017-04-14 12:21:58 Error: [InvalidArgumentException] Transport config "Debug" is missing. in /my/project/path/vendor/cakephp/cakephp/src/Mailer/Email.php on line 1525

After going through code, I found that it is expected to create a Email config named 'Default' to preview emails. It could have saved some time if it was mentioned in the documentation. Much better would be to make it configurable - so that developer can change it to whatever without editing the code.

When I created 'Debug' transport, I got following error:

PHP Fatal error:  Cannot use object of type stdClass as array in /my/project/path/vendor/lorenzo/cakephp-email-queue/src/Shell/previewShell.php on line 71

Also noted that it is sending emails in preview mode. It would have been really helpful if sending emails was optional. Sometimes we don't want to send mails, but view only the content is being formatted properly.

So in short:

  • Remove hardcoded word 'Debug', make it user configurable
  • Fix use of array for Object
  • Sending emails in preview should be optional

Cakephp 3.6 upgrade

Hello,

Do you have any plans on upgrading this plugin to work with Cakephp 3.6?
Thanks!

Extend funkcionality

Pleas create timestamp where email is realy send
Pleas create function for console, where delete sended records.
Thenks

composer downloading old version

When I run

composer require lorenzo/cakephp-email-queue

I get a old version of the plugin. Says it's Installing lorenzo/cakephp-email-queue (3.1.3). Which I guess is the latest numbered version. Is current master ready to bump to 3.1.4?

template_vars callback function

Jose,
would you consider adding a user defined callback function in SenderShell::main() for template_vars - before send() is called?

I use Emojione, and in db I store icons in so called 'short' format i.e. : thumbs : : zap : : computer :,
but email requires icons in Unicode format.
I need to convert them between db read and send().

Do you think this would be useful also for others?

I can try to implement it and create pull request.
If so, please give me a hint where to store the user function? Should I add it to the OptionParser?

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.