| 1 | package Daje::Tools::Mail::Manager; | ||
| 2 | use Mojo::Base -base, -signatures; | ||
| 3 | use v5.42; | ||
| 4 | |||
| 5 | |||
| 6 | # NAME | ||
| 7 | # ==== | ||
| 8 | # | ||
| 9 | # Daje::Tools::Mail::Manager - A mail manager | ||
| 10 | # | ||
| 11 | # SYNOPSIS | ||
| 12 | # ======== | ||
| 13 | #; | ||
| 14 | # | ||
| 15 | # DESCRIPTION | ||
| 16 | # =========== | ||
| 17 | # | ||
| 18 | # Daje::Tools::Mail::Manager is a Daje workflow activity. | ||
| 19 | # | ||
| 20 | # METHODS | ||
| 21 | # ======= | ||
| 22 | # | ||
| 23 | # | ||
| 24 | # activity | ||
| 25 | # | ||
| 26 | # SEE ALSO | ||
| 27 | # ======== | ||
| 28 | # | ||
| 29 | # Mojolicious, Mojolicious::Guides, https://mojolicious.org. | ||
| 30 | # | ||
| 31 | # LICENSE | ||
| 32 | # ======= | ||
| 33 | # | ||
| 34 | # Copyright (C) janeskil1525. | ||
| 35 | # | ||
| 36 | # This library is free software; you can redistribute it and/or modify | ||
| 37 | # it under the same terms as Perl itself. | ||
| 38 | # | ||
| 39 | # AUTHOR | ||
| 40 | # ====== | ||
| 41 | # | ||
| 42 | # janeskil1525 E<lt>janeskil1525@gmail.com | ||
| 43 | # | ||
| 44 | use Daje::Database::View::vMailFallbackSettings; | ||
| 45 | use Daje::Document::Builder; | ||
| 46 | use Daje::Tools::Mail::Sender; | ||
| 47 | |||
| 48 | has 'db'; | ||
| 49 | has 'error'; | ||
| 50 | |||
| 51 | sub verify_simple($self, $recipient, $code) { | ||
| 52 | my $data->{code} = $code; | ||
| 53 | my $mail->{message} = @{$self->_build_mail( | ||
| 54 | 'Daje::Documents::Templates::Mail::Verify::VerifyLogin', | ||
| 55 | 'verify_simple', | ||
| 56 | $data | ||
| 57 | )}[0]->{document}; | ||
| 58 | $mail->{recipients} = $recipient; | ||
| 59 | $mail->{subject} = "Daje login"; | ||
| 60 | $self->_send_mail($mail); | ||
| 61 | |||
| 62 | } | ||
| 63 | |||
| 64 | sub _send_mail($self, $mail) { | ||
| 65 | my $settings = Daje::Database::View::vMailFallbackSettings->new( | ||
| 66 | db => $self->db | ||
| 67 | )->load_mail_fallback_settings_pkey(1)->{data}; | ||
| 68 | |||
| 69 | my $sender = Daje::Tools::Mail::Sender->new( | ||
| 70 | host => $settings->{host}, | ||
| 71 | account => $settings->{username}, | ||
| 72 | password => $settings->{password}, | ||
| 73 | )->send_mail($mail); | ||
| 74 | |||
| 75 | } | ||
| 76 | |||
| 77 | sub _build_mail ($self, $source, $data_sections, $data) { | ||
| 78 | |||
| 79 | my $builder = Daje::Document::Builder->new( | ||
| 80 | source => $source, | ||
| 81 | data_sections => $data_sections, | ||
| 82 | data => $data, | ||
| 83 | error => $self->error() | ||
| 84 | ); | ||
| 85 | |||
| 86 | $builder->process(); | ||
| 87 | |||
| 88 | return $builder->output(); | ||
| 89 | } | ||
| 90 | 1; |