[Rt-commit] r10101 - in rt/branches/3.7-EXPERIMENTAL: .
ruz at bestpractical.com
ruz at bestpractical.com
Mon Dec 24 18:51:49 EST 2007
Author: ruz
Date: Mon Dec 24 18:51:48 2007
New Revision: 10101
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm
Log:
r9934 at cubic-pc (orig r9933): ruz | 2007-12-13 17:54:59 +0300
fix sending emails via SMTP
* MIME::Entity->send doesn't handle SMTP in the right way
* there is smtpsend method, however it doesn't work right
and send bodies as one line
* use Net::SMTP directly
* use streams instead scalars to avoid high memory usage
Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm Mon Dec 24 18:51:48 2007
@@ -443,6 +443,46 @@
return 0;
}
}
+ elsif ( $mail_command eq 'smtp' ) {
+ require Net::SMTP;
+ my $smtp = do { local $@; eval { Net::SMTP->new(
+ Host => RT->Config->Get('SMTPServer'),
+ Debug => RT->Config->Get('SMTPDebug'),
+ ) } };
+ unless ( $smtp ) {
+ $RT::Logger->crit( "Could not connect to SMTP server.");
+ return 0;
+ }
+
+ # duplicate head as we want drop Bcc field
+ my $head = $args{'Entity'}->head->dup;
+ my @recipients = map $_->address, Mail::Address->parse(
+ map $head->get($_), qw(To Cc Bcc)
+ );
+ $head->delete('Bcc');
+
+ my $sender = RT->Config->Get('SMTPFrom')
+ || $args{'Entity'}->head->get('From');
+ chomp $sender;
+
+ my $status = $smtp->mail( $sender )
+ && $smtp->recipient( @recipients );
+
+ if ( $status ) {
+ $smtp->data;
+ my $fh = $smtp->tied_fh;
+ $head->print( $fh );
+ print $fh "\n";
+ $args{'Entity'}->print_body( $fh );
+ $smtp->dataend;
+ }
+ $smtp->quit;
+
+ unless ( $status ) {
+ $RT::Logger->crit( "$msgid: Could not send mail via SMTP." );
+ return 0;
+ }
+ }
else {
local ($ENV{'MAILADDRESS'}, $ENV{'PERL_MAILERS'});
@@ -451,11 +491,6 @@
$ENV{'PERL_MAILERS'} = RT->Config->Get('SendmailPath');
push @mailer_args, split(/\s+/, RT->Config->Get('SendmailArguments'));
}
- elsif ( $mail_command eq 'smtp' ) {
- $ENV{'MAILADDRESS'} = RT->Config->Get('SMTPFrom') || $args{'Entity'}->head->get('From');
- push @mailer_args, ( Server => RT->Config->Get('SMTPServer') );
- push @mailer_args, ( Debug => RT->Config->Get('SMTPDebug') );
- }
else {
push @mailer_args, RT->Config->Get('MailParams');
}
More information about the Rt-commit
mailing list