+  # create journal and link to record
+  $self->{journalentry} = $self->_store_in_journal;
+  $self->_create_record_link if $self->{journalentry};
+
+  return $ok ? '' : ($error || "undefined error");
+}
+
+sub _all_recipients {
+  my ($self) = @_;
+  $self->{addresses} ||= {};
+  return map { @{ $self->{addresses}->{$_} || [] } } qw(to cc bcc);
+}
+
+sub _store_in_journal {
+  my ($self, $status, $extended_status) = @_;
+
+  my $journal_enable = $::instance_conf->get_email_journal;
+
+  return if $journal_enable == 0;
+
+  $status          //= $self->{driver}->status if $self->{driver};
+  $status          //= 'failed';
+  $extended_status //= $self->{driver}->extended_status if $self->{driver};
+  $extended_status //= 'unknown error';
+
+  my $headers = join "\r\n", (bundle_by { join(': ', @_) } 2, @{ $self->{headers} || [] });
+
+  my $jentry = SL::DB::EmailJournal->new(
+    sender          => SL::DB::Manager::Employee->current,
+    from            => $self->{from}    // '',
+    recipients      => join(', ', $self->_all_recipients),
+    subject         => $self->{subject} // '',
+    headers         => $headers,
+    body            => $self->{message} // '',
+    sent_on         => DateTime->now_local,
+    attachments     => \@{ $self->{mail_attachments} },
+    status          => $status,
+    extended_status => $extended_status,
+  )->save;
+  return $jentry->id;
+}
+
+
+sub _create_record_link {
+  my ($self) = @_;
+
+  # check for custom/overloaded types and ids (form != controller)
+  my $record_type = $self->{record_type} || $::form->{type};
+  my $record_id   = $self->{record_id}   || $::form->{id};
+
+  # you may send mails for unsaved objects (no record_id => unlinkable case)
+  if ($self->{journalentry} && $record_id && exists($type_to_table{$record_type})) {
+    RecordLinks->create_links(
+      mode       => 'ids',
+      from_table => $type_to_table{$record_type},
+      from_ids   => $record_id,
+      to_table   => 'email_journal',
+      to_id      => $self->{journalentry},
+    );
+  }