Revision d63305ba
Von Jan Büren vor mehr als 6 Jahren hinzugefügt
SL/Mailer.pm | ||
---|---|---|
45 | 45 |
smtp => 'SL::Mailer::SMTP', |
46 | 46 |
); |
47 | 47 |
|
48 |
my %type_to_table = ( |
|
49 |
sales_quotation => 'oe', |
|
50 |
request_quotation => 'oe', |
|
51 |
sales_order => 'oe', |
|
52 |
purchase_order => 'oe', |
|
53 |
invoice => 'ar', |
|
54 |
credit_note => 'ar', |
|
55 |
purchase_invoice => 'ap', |
|
56 |
letter => 'letter', |
|
57 |
purchase_delivery_order => 'delivery_orders', |
|
58 |
sales_delivery_order => 'delivery_orders', |
|
59 |
); |
|
60 |
|
|
48 | 61 |
sub new { |
49 | 62 |
my ($type, %params) = @_; |
50 | 63 |
my $self = { %params }; |
... | ... | |
263 | 276 |
|
264 | 277 |
$error = $@ if !$ok; |
265 | 278 |
|
279 |
# create journal and link to record |
|
266 | 280 |
$self->{journalentry} = $self->_store_in_journal; |
281 |
$self->_create_record_link if $self->{journalentry}; |
|
267 | 282 |
|
268 | 283 |
return $ok ? '' : ($error || "undefined error"); |
269 | 284 |
} |
... | ... | |
303 | 318 |
return $jentry->id; |
304 | 319 |
} |
305 | 320 |
|
321 |
|
|
322 |
sub _create_record_link { |
|
323 |
my ($self) = @_; |
|
324 |
|
|
325 |
# check for custom/overloaded types and ids (form != controller) |
|
326 |
my $record_type = $self->{record_type} || $::form->{type}; |
|
327 |
my $record_id = $self->{record_id} || $::form->{id}; |
|
328 |
|
|
329 |
# you may send mails for unsaved objects (no record_id => unlinkable case) |
|
330 |
if ($self->{journalentry} && $record_id && exists($type_to_table{$record_type})) { |
|
331 |
RecordLinks->create_links( |
|
332 |
mode => 'ids', |
|
333 |
from_table => $type_to_table{$record_type}, |
|
334 |
from_ids => $record_id, |
|
335 |
to_table => 'email_journal', |
|
336 |
to_id => $self->{journalentry}, |
|
337 |
); |
|
338 |
} |
|
339 |
} |
|
340 |
|
|
306 | 341 |
1; |
342 |
|
|
343 |
|
|
344 |
__END__ |
|
345 |
|
|
346 |
=pod |
|
347 |
|
|
348 |
=encoding utf8 |
|
349 |
|
|
350 |
=head1 NAME |
|
351 |
|
|
352 |
SL::Mailer - Base class for sending mails from kivitendo |
|
353 |
|
|
354 |
=head1 SYNOPSIS |
|
355 |
|
|
356 |
package SL::BackgroundJob::CreatePeriodicInvoices; |
|
357 |
|
|
358 |
use SL::Mailer; |
|
359 |
|
|
360 |
my $mail = Mailer->new; |
|
361 |
$mail->{from} = $config{periodic_invoices}->{email_from}; |
|
362 |
$mail->{to} = $email; |
|
363 |
$mail->{subject} = $config{periodic_invoices}->{email_subject}; |
|
364 |
$mail->{content_type} = $filename =~ m/.html$/ ? 'text/html' : 'text/plain'; |
|
365 |
$mail->{message} = $output; |
|
366 |
|
|
367 |
$mail->send; |
|
368 |
|
|
369 |
=head1 OVERVIEW |
|
370 |
|
|
371 |
Mail can be send from kivitendo via the sendmail command or the smtp protocol. |
|
372 |
|
|
373 |
|
|
374 |
=head1 INTERNAL DATA TYPES |
|
375 |
|
|
376 |
|
|
377 |
=over 2 |
|
378 |
|
|
379 |
=item C<%mail_delivery_modules> |
|
380 |
|
|
381 |
Currently two modules are supported either smtp or sendmail. |
|
382 |
|
|
383 |
=item C<%type_to_table> |
|
384 |
|
|
385 |
Due to the lack of a single global mapping for $form->{type}, |
|
386 |
type is mapped to the corresponding database table. All types which |
|
387 |
implement a mail action are currently mapped and should be mapped. |
|
388 |
Type is either the value of the old form or the newer controller |
|
389 |
based object type. |
|
390 |
|
|
391 |
=back |
|
392 |
|
|
393 |
=head1 FUNCTIONS |
|
394 |
|
|
395 |
=over 4 |
|
396 |
|
|
397 |
=item C<new> |
|
398 |
|
|
399 |
=item C<_create_driver> |
|
400 |
|
|
401 |
=item C<_cleanup_addresses> |
|
402 |
|
|
403 |
=item C<_create_address_headers> |
|
404 |
|
|
405 |
=item C<_create_message_id> |
|
406 |
|
|
407 |
=item C<_create_attachment_part> |
|
408 |
|
|
409 |
=item C<_create_message> |
|
410 |
|
|
411 |
=item C<send> |
|
412 |
|
|
413 |
If a mail was send successfully the internal functions _store_in_journal |
|
414 |
is called if email journaling is enabled. If _store_in_journal was executed |
|
415 |
successfully and the calling form is already persistent (database id) a |
|
416 |
record_link will be created. |
|
417 |
|
|
418 |
=item C<_all_recipients> |
|
419 |
|
|
420 |
=item C<_store_in_journal> |
|
421 |
|
|
422 |
=item C<_create_record_link $self->{journalentry}, $::form->{id}, $self->{record_id}> |
|
423 |
|
|
424 |
|
|
425 |
If $self->{journalentry} and either $self->{record_id} or $::form->{id} (checked in |
|
426 |
this order) exists a record link from record to email journal is created. |
|
427 |
Will fail silently if record_link creation wasn't successful (same behaviour as |
|
428 |
_store_in_journal). |
|
429 |
|
|
430 |
=item C<validate> |
|
431 |
|
|
432 |
=back |
|
433 |
|
|
434 |
=head1 BUGS |
|
435 |
|
|
436 |
Nothing here yet. |
|
437 |
|
|
438 |
=head1 AUTHOR |
|
439 |
|
|
440 |
=cut |
Auch abrufbar als: Unified diff
Verknüpfte Belege um die Verknüpfung 'E-Mail Journal' erweitert.
Falls das E-Mail-Journal aktiviert ist wird zusätzlich zu der
archivierten E-Mail auch die Verknüpfung vom Beleg zu der E-Mail mitgespeichert
und ist im Beleg zusätzlich direkt anwählbar.
Etwas mehr Details im POD vom Mailer.pm, die Implementierung orientiert
sich überwiegend an der Erweiterung der Verknüpfung von Letter.pm, bzw. dem ShopConnector.