+
+ unless ( length($error) ) {
+
+ local $SIG{__DIE__}; # don't want Mason __DIE__ handler active
+ local $@; # just in case
+ eval { sendmail($message, { transport => $transport,
+ from => $from,
+ to => \@env_to }) };
+
+ if (ref($@) and $@->isa('Email::Sender::Failure')) {
+ $error = $@->code.' ' if $@->code;
+ $error .= $@->message;
+ } else {
+ $error = $@;
+ }
+
+ }
+
+ # Logging
+ if ( $conf->exists('log_sent_mail') ) {
+ my $cust_msg = FS::cust_msg->new({
+ 'env_from' => $options{'from'},
+ 'env_to' => join(', ', @env_to),
+ 'header' => $message->header_as_string,
+ 'body' => $message->body_as_string,
+ '_date' => $time,
+ 'error' => $error,
+ 'custnum' => $options{'custnum'},
+ 'msgnum' => $options{'msgnum'},
+ 'status' => ($error ? 'failed' : 'sent'),
+ 'msgtype' => $options{'msgtype'},
+ });
+ my $log_error = $cust_msg->insert;
+ warn "Error logging message: $log_error\n" if $log_error; # at least warn