Line # Revision Author
1 296 ahitrov <%args>
2
3 $email => undef
4
5 </%args>
6 <%init>
7
8 return unless ref $email;
9
10 use MIME::Lite;
11 use MIME::Base64;
12
13 my $subject = $email->{subject};
14 $subject = MIME::Base64::encode($subject);
15 $subject =~ s/\s+$//si;
16 $subject = '=?utf-8?B?'.$subject.'?=';
17
18 my $emailfrom;
19 my ($from, $efrom) = $email->{from} =~ /^(.*?)<(.*?)>/ ? ($1, $2) : $email->{from} =~ /<(.*?)>/ ? ('',$1) : ('',$email->{from});
20 if ( $from ) {
21 $from = MIME::Base64::encode($from);
22 $from =~ s/\s+$//si;
23 $from = '=?utf-8?B?'.$from.'?=';
24 $emailfrom = $from.' <'.$efrom.'>';
25 } else {
26 $emailfrom = $efrom;
27 }
28
29 my $emailto;
30 my ($to, $eto) = $email->{to} =~ /^(.*?)<(.*?)>/ ? ($1, $2) : $email->{to} =~ /<(.*?)>/ ? ('',$1) : ('',$email->{to});
31 if ( $to ) {
32 $to = MIME::Base64::encode($to);
33 $to =~ s/\s+$//si;
34 $to = '=?utf-8?B?'.$to.'?=';
35 $emailto = $to.' <'.$eto.'>';
36 } else {
37 $emailto = $eto;
38 }
39
40 my $body = $email->{body};
41 # warn Dumper($email);
42 my $dt = Contenido::DateTime->new;
43 $dt->set_locale('en_US');
44 $dt->set_time_zone('Europe/Moscow');
45
46 my $pdate = $dt->strftime("%a, %d %b %Y %H:%M:%S %z");
47 my $msg = MIME::Lite->new(
48 To => $emailto,
49 From => $emailfrom,
50 Subject => $subject,
51 Encoding=> 'binary',
52 Date => $pdate,
53 Type => 'multipart/related;type="multipart/alternative";charset="utf-8"',
54 );
55 $msg->attach(
56 'Type' => 'text/html;charset="utf-8"',
57 'Data' => $body,
58 'Disposition' => '',
59 );
60
61 $msg->send();
62
63 </%init>