ironcamel / Dancer-Plugin-Email

Simple email sending for Dancer
http://p3rl.org/Dancer::Plugin::Email
6 stars 10 forks source link

Asynchronous send? #7

Open kalgan opened 12 years ago

kalgan commented 12 years ago

Before of all, thank you for this great plugin! :)

I have a suggestion to add an option to send emails asynchronously. Now, when sending email, the server waits for completion.

I'm using for this Proc::Simple::Async, then this process will go into background:

use Dancer::Plugin::Email;
use Proc::Simple::Async;

get '/emailme' => sub
{

    my $proc = async
    {
        my $msg = email {
            from    => 'robot@example.com',
            to      => 'user@example.com',
            subject => 'Async email',
            message => 'Hello!'
            };
        return $msg;
    }
    return 'message sent!';
};
ironcamel commented 12 years ago

This is a great idea, thanks! I am thinking that it could work like this:

my $msg = email {
    async   => 1,
    from    => 'robot@example.com',
    to      => 'user@example.com',
    subject => 'Async email',
    message => 'Hello!'
};