|
|
@ -18,19 +18,24 @@ sub new { |
|
|
|
return bless($self, $class); |
|
|
|
return bless($self, $class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub send { |
|
|
|
sub create { |
|
|
|
my ($self, $to, $subject, $body) = @_; |
|
|
|
my ($self, $to, $subject, $body) = @_; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Email::Simple->create( |
|
|
|
|
|
|
|
body => $body, header => [ |
|
|
|
|
|
|
|
From => $self->{from}, |
|
|
|
|
|
|
|
'Reply-To' => $self->{reply} || $self->{from}, |
|
|
|
|
|
|
|
To => $to, |
|
|
|
|
|
|
|
Subject => $subject, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
)->as_string; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub send { |
|
|
|
|
|
|
|
my ($self, $to, $email) = @_; |
|
|
|
|
|
|
|
|
|
|
|
eval { |
|
|
|
eval { |
|
|
|
my $email = Email::Simple->create( |
|
|
|
sendmail($email, {from => $self->{from}, to => $to}); 1; |
|
|
|
header => [ |
|
|
|
|
|
|
|
From => $self->{from}, |
|
|
|
|
|
|
|
'Reply-To' => $self->{reply} || $self->{from}, |
|
|
|
|
|
|
|
To => $to, |
|
|
|
|
|
|
|
Subject => $subject, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
body => $body); |
|
|
|
|
|
|
|
sendmail($email, {from => $self->{from}}); 1; |
|
|
|
|
|
|
|
} or do { |
|
|
|
} or do { |
|
|
|
return $@->message if ref $@; |
|
|
|
return $@->message if ref $@; |
|
|
|
return $@; |
|
|
|
return $@; |
|
|
@ -54,10 +59,21 @@ LDV::Email -- simple wrapper class to work with emails |
|
|
|
* from -- default 'From' header |
|
|
|
* from -- default 'From' header |
|
|
|
* reply -- reply to this email instead 'from' |
|
|
|
* reply -- reply to this email instead 'from' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=head2 C<create> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $email = LDV::Email->new(\%opts); |
|
|
|
|
|
|
|
my $text = $email->create($to, $subject, $body); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Create email message with some defaults set. |
|
|
|
|
|
|
|
Returns message text (with headers). |
|
|
|
|
|
|
|
|
|
|
|
=head2 C<send> |
|
|
|
=head2 C<send> |
|
|
|
|
|
|
|
|
|
|
|
my $email = LDV::Email->new(\%opts); |
|
|
|
my $email = LDV::Email->new(\%opts); |
|
|
|
my $error = $email->send($to, $subject, $body); |
|
|
|
my $error = $email->send($to, $email); |
|
|
|
die($result) if $error; |
|
|
|
die($result) if $error; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Send previously created email. |
|
|
|
|
|
|
|
Return nothing on success or scalar with description on error. |
|
|
|
|
|
|
|
|
|
|
|
=cut |
|
|
|
=cut |
|
|
|