ironcamel / Dancer-Plugin-Email

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

Dancer::Plugin::Email problem with checking email failures #6

Closed agordon closed 12 years ago

agordon commented 13 years ago

Hello,

I'm having problems checking the return status of email sending with "Dancer::Plugin::Email" .

The first example in the "code recipes" of "Dancer::Plugin::Email" shows the following:

post '/contact' => sub {

    my $msg = email {
        to => '...',
        subject => '...',
        message => $msg,
        encoding => 'base64',
        attach => [ '/path/to/file' ]
    };

    warn $msg->{string} if $msg->{type} eq 'failure';

};

This is the actual code I used:

get '/emailtest' => sub {
    my $msg = email {
            to => 'gordon\@cshl.edu',
            subject => 'Dancer::PlugIn::Email Test',
            message => "Hello World from Dancer::Plugin::Email",
    };
    warn $msg->{string} if $msg->{type} eq 'failure';
    return "Email Sent!\n";
};

This is the error I get: Warning caught during route execution: Use of uninitialized value in string eq at /home/gordon/projects/perl_dancer_test /user_email_verification/lib/user_email_verification.pm line 80.

/home/gordon/projects/perl_dancer_test/user_email_verification/lib/user_email_verification.pm around line 80
77      subject => 'Dancer::PlugIn::Email Test',
78      message => "Hello World from Dancer::Plugin::Email",
79  };
80  warn $msg->{string} if $msg->{type} eq 'failure';
81  return "Email Sent!\n";
82 };
83 

Trying to dig a little deeper, it seems "$msg" is a "Return::Value" object, and that class is deprecated.

Also, "$msg->{type}" returns an empty string (so it's not the problem), but "$msg->{string}" returns undef. and "Data::Dumper($msg)" gives:

 $VAR1 = bless( {
             'prop' => {},
             'string' => 'success',
             'type' => 'success',
             'errno' => undef
           }, 'Return::Value' );

I'm using Perl 5.10.1 , Dancer 1.3702, Dancer::Plugin::Email 0.1300 .

ironcamel commented 13 years ago

Thanks for the detailed description. I will try to see if there is a short term solution to this. In the long term, I am seriously considering doing a major rewrite which will use Email::Sender instead of Email::Send. This will remove the Return::Value stuff. See issue #5 for more background.

ironcamel commented 12 years ago

I have finally done a major refactor of this plugin to use Email::Sender. Now, calling the email() function will invoke Email::Sender::Simple's sendmail function, which will throw an exception on failure. Please try the new version and make sure everything still works for you. I have made a dev release to CPAN. You could also checkout the latest master branch.