-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemail.pl
More file actions
executable file
·36 lines (36 loc) · 952 Bytes
/
email.pl
File metadata and controls
executable file
·36 lines (36 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl
#basic email sender utility with msmtp
#proper configuration expected in ~/.msmtprc
use strict;
use Getopt::Std;
my $usage=q{Usage:
email.pl [-s '<subject>'] [-b '<body_text>'] \
[-f <file_to_include_in_body>] <to@email.com>
};
my %v=();
getopts('s:b:f:', \%v) || die "$usage\n";
my $to=shift(@ARGV) ||
die("${usage}Error: desination email required!\n");
my $subj=$v{s} || '[no subject]';
my $body=$v{b};
my $fname=$v{f};
if ($fname && $fname ne '-') {
die("Error: file $fname not found!\n")
unless -f $fname;
}
my $etxt="To: <$to>\n";
$etxt.="Subject: $subj\n\n";
$etxt.=$body if $body;
open(MSMTP, "| msmtp --tls-certcheck=off -t '$to'")
|| die("Error opening the msmtp pipe!\n");
print MSMTP "$etxt\n";
if ($fname) {
@ARGV=();
print MSMTP "\n" if $body;
if ($fname ne '-') {
@ARGV=($fname);
#print MSMTP "-------- content of $fname follows: --------\n";
}
print MSMTP $_ while (<>);
}
close(MSMTP);