DevTech101

DevTech101

How to Email Attachments in Perl

Below as a small snipped that can be used to email attachments

sub Mail {
# Handles attachments
#
my($from, $to, $subject, $body, @attachments) = @_;
my $cmd = '/util/sendEmail';
foreach $attachment (@ARGV) { $cmd .= qq# -a "$attachment"# if -r "$attachment"; }
$cmd .= qq# -u "$subject"#      if $subject;
$cmd .= qq# -f "$from"#         if $from;
$cmd .= qq# -t "$to"#           if $to;
$cmd .= $body ? qq# -m "$body"# : '</dev/null';
$out = `$cmd`;
return "SUCCESS: Mail sent to $to" if $out =~ /Email sent successfully/;
return "ERROR: sendEmail failure - $out";
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
%d bloggers like this: