-
Notifications
You must be signed in to change notification settings - Fork 5
/
send_gmail_with_attachment.perl
executable file
·66 lines (55 loc) · 1.79 KB
/
send_gmail_with_attachment.perl
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl
# install perl module under pfSense with
# 1. setenv PACKAGESITE to matching pfSense version
# 2. pkg_add -r p5-Net-SMTP-TLS
# edit /usr/local/lib/perl5/site_perl/5.12.4/Net/SMTP/TLS.pm as in http://www.perlmonks.org/?node_id=929055
use Net::SMTP::TLS;
my $SUBJECT=$ARGV[0];
my $DATA_FILE = $ARGV[1];
my $FILENAME=$ARGV[2];
my $CONTENTTYPE=$ARGV[3];
my $BODY=$ARGV[4];
my $attachFile = 'attachment';
my $boundary = 'frontier';
open(DATA, $DATA_FILE) || die("Could not open the file");
binmode FILE;
my ($buf, $data, $n);
while (($n = read DATA, $data, 4) != 0) {
$buf .= $data;
}
close(DATA);
my $SENDER='[email protected]';
my $RECEIVER='[email protected]';
#my $PASSWORD='changeme';
open FILE, "</home/pfSensePortal/config_gmail.txt";
$PASSWORD = do { local $/; <FILE> };
my $SMTP='smtp.gmail.com';
my $HELLO='smtp.gmail.com';
my $PORT=587;
my $mailer = new Net::SMTP::TLS(
$SMTP,
Hello =>$HELLO,
Port=>$PORT,
User=>$SENDER,
Password=>$PASSWORD);
$mailer->mail($SENDER);
$mailer->to($RECEIVER);
$mailer->data;
$mailer->datasend("From: " . $SENDER . "\n");
$mailer->datasend("To: " . $RECEIVER . "\n");
$mailer->datasend("Subject: " . $SUBJECT . "\n");
$mailer->datasend("MIME-Version: 1.0\n");
$mailer->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundary\"\n");
$mailer->datasend("\n");
$mailer->datasend("--$boundary\n");
$mailer->datasend("Content-type: text/plain\n");
$mailer->datasend("Content-Disposition: quoted-printable\n");
$mailer->datasend("\n$BODY\n\n");
$mailer->datasend("--$boundary\n");
$mailer->datasend("Content-Type: $CONTENTTYPE; name=\"$FILENAME\"\n");
$mailer->datasend("Content-Disposition: attachment; filename=\"$FILENAME\"\n");
$mailer->datasend("\n");
$mailer->datasend("$buf\n");
$mailer->datasend("--$boundary--\n");
$mailer->dataend();
$mailer->quit;