Switch to Mojolicious::Plugin::Mail

Close #81
master
root 10 years ago committed by Daniel Berteaud
parent 232125b88c
commit b4497a1e80
  1. 90
      lib/Mojolicious/Plugin/Mailer.pm
  2. 73
      public/vroom.pl
  3. 7
      templates/default/feedback.email_text.ep
  4. 0
      templates/default/feedback.mail.ep
  5. 32
      templates/default/invite.email_text.ep
  6. 0
      templates/default/invite.mail.ep
  7. 17
      templates/default/notification.email_text.ep
  8. 0
      templates/default/notification.mail.ep

@ -1,90 +0,0 @@
package Mojolicious::Plugin::Mailer;
use Mojo::Base 'Mojolicious::Plugin';
use strict;
use warnings;
use Email::MIME;
use Email::Sender::Simple;
use Email::Sender::Transport::Test;
use Encode;
use utf8;
our $VERSION = '0.05';
sub register {
my ($self, $app, $conf) = @_;
$app->helper(
email => sub {
my $self = shift;
my $args = @_ ? { @_ } : return;
my @data = @{ $args->{data} };
my @parts = (
Email::MIME->create(
body => Encode::encode('UTF-8', $self->render(
@data,
format => $args->{format} ? $args->{format} : 'email_text',
partial => 1
)),
attributes => {
charset => 'utf-8',
encoding => '7bit',
content_type => 'text/plain',
}
),
Email::MIME->create(
body => Encode::encode('UTF-8', $self->render(
@data,
format => $args->{format} ? $args->{format} : 'email_html',
partial => 1
)),
attributes => {
charset => 'utf-8',
encoding => '7bit',
content_type => 'text/html',
}
),
);
my $transport = defined $args->{transport} || $conf->{transport}
? $args->{transport} || $conf->{transport}
: undef;
my $header = { @{ $args->{header} } };
$header->{From} ||= $conf->{from};
$header->{Subject} ||= $self->stash('title');
my $email = Email::MIME->create(
header => [ %{$header} ],
parts => [ @parts ]
);
$email->charset_set ( $args->{charset} ? $args->{charset} : 'utf-8' );
$email->content_type_set( $args->{content_type} ? $args->{content_type} : 'multipart/alternative' );
return Email::Sender::Simple->try_to_send( $email, { transport => $transport } ) if $transport;
my $emailer = Email::Sender::Transport::Test->new;
$emailer->send_email(
$email,
{
to => [ $header->{To} ],
from => $header->{From}
}
);
return unless $emailer->{deliveries}->[0]->{successes}->[0];
}
);
}
1;
__END__

@ -7,13 +7,12 @@
use lib '../lib';
use Mojolicious::Lite;
use Mojolicious::Plugin::Mailer;
use Mojolicious::Plugin::Mail;
use Mojo::JSON;
use DBI;
use Digest::MD5 qw(md5_hex);
use Crypt::SaltedHash;
use MIME::Base64;
use Email::Sender::Transport::Sendmail;
use Encode;
use File::stat;
use File::Basename;
@ -208,12 +207,10 @@ plugin I18N => {
support_url_langs => [qw(en fr)]
};
# Load mailer plugin with its default values
plugin Mailer => {
from => $config->{emailFrom},
transport => Email::Sender::Transport::Sendmail->new({
sendmail => $config->{sendmail}
})
# Load mail plugin with its default values
plugin mail => {
from => $config->{emailFrom},
type => 'text/html',
};
# Wrapper arround DBI
@ -912,16 +909,13 @@ post '/feedback' => sub {
my $self = shift;
my $email = $self->param('email') || '';
my $comment = $self->param('comment');
$self->email(
header => [
Subject => encode("MIME-Header", $self->l("FEEDBACK_FROM_VROOM")),
To => $config->{feedbackRecipient}
],
data => [
template => 'feedback',
email => $email,
comment => $comment
],
my $sent = $self->mail(
to => $config->{feedbackRecipient},
subject => $self->l("FEEDBACK_FROM_VROOM"),
data => $self->render_mail('feedback',
email => $email,
comment => $comment
)
);
$self->redirect_to($self->get_url('feedback_thanks'));
};
@ -1217,19 +1211,17 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub {
}
else{
my $inviteId = $self->add_invitation($room,$rcpt);
if ($inviteId && $self->email(
header => [
Subject => encode("MIME-Header", $self->l("EMAIL_INVITATION")),
To => $rcpt
],
data => [
template => 'invite',
room => $room,
message => $message,
inviteId => $inviteId,
joinPass => ($data->{join_password}) ? 'yes' : 'no'
],
)){
my $sent = $self->mail(
to => $rcpt,
subject => $self->l("EMAIL_INVITATION"),
data => $self->render_mail('invite',
room => $room,
message => $message,
inviteId => $inviteId,
joinPass => ($data->{join_password}) ? 'yes' : 'no'
)
);
if ($inviteId && $sent){
$self->app->log->info($self->session('name') . " sent an invitation for room $room to $rcpt");
$status = 'success';
$msg = sprintf($self->l('INVITE_SENT_TO_s'), $rcpt);
@ -1491,17 +1483,14 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub {
my $subj = ($name eq '') ? sprintf($self->l('s_JOINED_ROOM_s'), $self->l('SOMEONE'), $room) : sprintf($self->l('s_JOINED_ROOM_s'), $name, $room);
# Send notifications
foreach my $rcpt ($self->get_notification($room)){
$self->email(
header => [
Subject => encode("MIME-Header", $subj),
To => $rcpt
],
data => [
template => 'notification',
room => $room,
name => $name
],
);
my $sent = $self->mail(
to => $rcpt,
subject => $subj,
data => $self->render_mail('notification',
room => $room,
name => $name
)
);
}
return $self->render(
json => {

@ -1,7 +0,0 @@
<%==l 'FROM' %>: <%= $email %>
<%==l 'COMMENT' %>: <%== $comment %>
--
<%==l 'EMAIL_SIGN' %>

@ -1,32 +0,0 @@
<%
my $url = $self->url_for('/')->to_abs;
$url .= ($url =~ m/\/$/) ? '' : '/';
%>
<%==l 'YOU_ARE_INVITED_TO_A_MEETING' %>
* <%=l 'A_MODERN_BROWSER' %>
* <%=l 'A_WEBCAM' %>
* <%=l 'A_MIC' %>
<%==l 'WHEN_YOU_ARE_READY' %>
<% my $roomAccess = $room;
if ($joinPass eq 'yes') {
$roomAccess .= '?token=' . $inviteId;
}
%>
<%== $url . $roomAccess %>
<% if ($message && $message ne ''){ %>
<%==l 'MESSAGE_FROM_ORGANIZER' %>:
<%== $message %>
<% } %>
<%==l 'IF_YOU_CANNOT_JOIN' %> <%==l 'YOU_CAN_NOTIFY_THE_ORGANIZER' %>
<%== $url . 'invitation?token=' . $inviteId %>
<%==l 'HAVE_A_NICE_MEETING' %>
--
<%==l 'EMAIL_SIGN' %>

@ -1,17 +0,0 @@
<%
my $url = $self->url_for('/')->to_abs;
$url .= ($url =~ m/\/$/) ? '' : '/';
%>
<%==l 'SOMEONE_JOINED_A_ROOM' %>
<% if ($name && $name ne ''){ %>
<%=l 'PARTICIPANT_NAME' %>: <%== $name %>
<% } %>
<%=l 'WHEN_YOU_ARE_READY' %>
<%== $url . $room %>
<%=l 'HAVE_A_NICE_MEETING' %>
--
<%==l 'EMAIL_SIGN' %>
Loading…
Cancel
Save