Skip to content

Commit 07d25bb

Browse files
committed
Sending emails using Email::MIME and Email::Sender::Simple
Because the original call to the sendmail stopped to work.
1 parent 96bd50f commit 07d25bb

2 files changed

Lines changed: 26 additions & 23 deletions

File tree

lib/WebTaskSubmitter/Email.pm

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package WebTaskSubmitter::Email;
22

33
use common::sense;
4-
use Mail::Sendmail;
4+
#use Mail::Sendmail;
5+
use Email::MIME;
6+
use Email::Sender::Simple qw(sendmail);
57
use Encode;
68
use Time::Piece;
79

@@ -18,25 +20,26 @@ sub new {
1820

1921
use utf8;
2022

21-
sub sendmail {
23+
sub send_email {
2224
my ($from, $to, $subject, $body) = @_;
2325

24-
$from = Encode::encode('MIME-Q', $from);
25-
$to = Encode::encode('MIME-Q', $to);
26-
$subject = Encode::encode('MIME-Q', $subject);
27-
28-
open(SENDMAIL, "| /usr/sbin/sendmail -t") or die("Failed to open pipe to sendmail: $!");
29-
binmode(SENDMAIL, ":utf8");
30-
print SENDMAIL <<"EOF";
31-
Content-Transfer-Encoding: 8bit
32-
Content-type: text/plain; charset=UTF-8
33-
Subject: $subject
34-
From: $from
35-
To: $to
36-
37-
$body
38-
EOF
39-
close (SENDMAIL);
26+
#my $efrom = Encode::encode('MIME-Header', $from);
27+
#my $eto = Encode::encode('MIME-Header', $to);
28+
#my $esubject = Encode::encode('MIME-Header', $subject);
29+
30+
my $message = Email::MIME->create(
31+
header_str => [
32+
From => $from,
33+
To => $to,
34+
Subject => $subject,
35+
],
36+
attributes => {
37+
encoding => 'quoted-printable',
38+
charset => 'UTF-8',
39+
},
40+
body_str => $body,
41+
);
42+
sendmail($message);
4043
}
4144

4245
sub get_url($$) {
@@ -74,7 +77,7 @@ sub notify_comment() {
7477
$body .= $texts->{email_footer};
7578
my $user = $self->{Model}->get_user($uid);
7679
utf8::decode($user->{name});
77-
sendmail($options->{emails_from}, sprintf("%s <%s>", $user->{name}, $user->{email}), $subject, $body);
80+
send_email($options->{emails_from}, sprintf("%s <%s>", $user->{name}, $user->{email}), $subject, $body);
7881
$sended = 1;
7982
}
8083

@@ -111,7 +114,7 @@ sub notify_points_changed() {
111114
$body .= $texts->{email_footer};
112115
my $user = $self->{Model}->get_user($uid);
113116
utf8::decode($user->{name});
114-
sendmail($options->{emails_from}, sprintf("%s <%s>", $user->{name}, $user->{email}), $subject, $body);
117+
send_email($options->{emails_from}, sprintf("%s <%s>", $user->{name}, $user->{email}), $subject, $body);
115118

116119
$sended = 1;
117120
}
@@ -179,7 +182,7 @@ sub send_prepared_notifications() {
179182

180183
$body .= $texts->{email_footer};
181184
utf8::decode($user->{name});
182-
sendmail($options->{emails_from}, sprintf("%s <%s>", $user->{name}, $user->{email}), $subject, $body);
185+
send_email($options->{emails_from}, sprintf("%s <%s>", $user->{name}, $user->{email}), $subject, $body);
183186
}
184187

185188
$self->{Model}->set_notifications_sended($max_nid);
@@ -200,7 +203,7 @@ sub send_renew_password_email() {
200203
);
201204
$body .= $texts->{email_footer};
202205

203-
sendmail($options->{emails_from}, sprintf("%s <%s>", $user->{name}, $user->{email}), $subject, $body);
206+
send_email($options->{emails_from}, sprintf("%s <%s>", $user->{name}, $user->{email}), $subject, $body);
204207
}
205208

206209
################################################################################

lib/WebTaskSubmitter/Worker.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ sub manage_mailer() {
297297
return unless $data->{mailer_send};
298298

299299
for my $target (@targets) {
300-
WebTaskSubmitter::Email::sendmail($options->{emails_from}, sprintf("%s <%s>", $target->{name}, $target->{email}), $data->{mailer_subject}, $data->{mailer_text});
300+
WebTaskSubmitter::Email::send_email($options->{emails_from}, sprintf("%s <%s>", $target->{name}, $target->{email}), $data->{mailer_subject}, $data->{mailer_text});
301301
}
302302

303303
$self->{Main}->redirect('mailer', {mailer_sended => 1});

0 commit comments

Comments
 (0)