11package WebTaskSubmitter::Email ;
22
33use common::sense;
4- use Mail::Sendmail;
4+ # use Mail::Sendmail;
5+ use Email::MIME;
6+ use Email::Sender::Simple qw( sendmail) ;
57use Encode;
68use Time::Piece;
79
@@ -18,25 +20,26 @@ sub new {
1820
1921use 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
4245sub 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# ###############################################################################
0 commit comments