forked from abh/rt-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmtp.patch
84 lines (79 loc) · 2.72 KB
/
smtp.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 1ef2ca771..09ffc7af2 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -63,6 +63,10 @@ use RT::Util 'safe_run_child';
use File::Spec;
use MIME::Words ();
use Scope::Upper qw/unwind HERE/;
+
+use Email::Sender ();
+use Email::Sender::Simple ();
+use Email::Sender::Transport::SMTP ();
use 5.010;
=head1 NAME
@@ -892,6 +896,8 @@ sub SendEmail {
}
my $mail_command = RT->Config->Get('MailCommand');
+ $RT::Logger->info("MailCommand: ", $mail_command);
+ $mail_command = "smtp";
# if it is a sub routine, we just return it;
return $mail_command->($args{'Entity'}) if UNIVERSAL::isa( $mail_command, 'CODE' );
@@ -929,6 +935,8 @@ sub SendEmail {
# if something wrong with $mail->print we will get PIPE signal, handle it
local $SIG{'PIPE'} = sub { die "program unexpectedly closed pipe" };
+ $RT::Logger->info("running sendmail: ", join(" ", $path, @args));
+
require IPC::Open2;
my ($mail, $stdout);
my $pid = IPC::Open2::open2( $stdout, $mail, $path, @args )
@@ -976,6 +984,50 @@ sub SendEmail {
print $fh "From $user\@localhost ".localtime()."\n";
print $fh $content, "\n";
close $fh;
+ } elsif ( $mail_command eq 'smtp' ) {
+
+ # TODO: if args{Bounce} ?
+
+ # SetOutgoingMailFrom is required for SMTP
+ my $sender = _OutgoingMailFrom($TicketObj);
+
+ # VERP
+ if ( $TransactionObj
+ and my $prefix = RT->Config->Get('VERPPrefix')
+ and my $domain = RT->Config->Get('VERPDomain'))
+ {
+ my $from = $TransactionObj->CreatorObj->EmailAddress;
+ $from =~ s/@/=/g;
+ $from =~ s/\s//g;
+ $sender = "$prefix$from\@$domain";
+ }
+
+
+ my @recipients = map $_->address, map Email::Address->parse($head->get($_)), qw(To Cc Bcc);
+ $args{'Entity'}->head->delete('Bcc');
+
+ eval {
+ Email::Sender::Simple->send(
+ $args{Entity},
+ { from => $sender,
+ to => \@recipients,
+ transport => Email::Sender::Transport::SMTP->new(
+ { host => 'localhost',
+ port => 25,
+ }
+ )
+ }
+ );
+ };
+
+ if ($@) {
+ $RT::Logger->crit("$msgid: Could not send mail with smtp: " . $@);
+ if ($TicketObj) {
+ _RecordSendEmailFailure($TicketObj);
+ }
+ return 0;
+ }
+
} else {
local ($ENV{'MAILADDRESS'}, $ENV{'PERL_MAILERS'});