forked from gorlak/p4admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerforceMail.pm
74 lines (57 loc) · 1.66 KB
/
PerforceMail.pm
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
66
67
68
69
70
71
72
73
74
package PerforceMail;
use strict;
# core libs
use Net::SMTP;
my $g_Server = $ENV{ P4ADMIN_MAILSERVER };
my $g_From = $ENV{ P4ADMIN_MAILFROM };
my $g_To = $ENV{ P4ADMIN_MAILTO };
sub SendMail
{
my %args = @_;
# connect to an SMTP server
my $smtp = Net::SMTP->new( $args{ Server } );
# use the sender's address here
$smtp->mail( $args{ From } );
# recipient's address
$smtp->to( $args{ To } );
# Start the mail
$smtp->data();
# Send the header
$smtp->datasend("To: $args{ To }\n");
$smtp->datasend("From: $args{ From }\n");
$smtp->datasend("Subject: $args{ Subject }\n");
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("Content-type: multipart/mixed;boundary=\"boundary\"\n");
# Send the body
$smtp->datasend("--boundary\n");
$smtp->datasend( $args{ Message } );
# Send the attachment
if ( defined $args{ Attachment } )
{
$smtp->datasend("--boundary\n");
$smtp->datasend("Content-type: text/plain\n");
$smtp->datasend("Content-Disposition: attachment; filename=\"$args{ Attachment }\"\n");
$smtp->datasend("Content-Type: application/text; name=$args{ Attachment }\n");
my $text;
open( TEXT, "$args{ Attachment }" );
while( my $line = <TEXT> ) { $text .= $line; }
$smtp->datasend($text);
}
# End the mail
$smtp->dataend();
# Close the SMTP connection
$smtp->quit;
}
sub SendMessage
{
my $subject = shift;
my $message = shift;
my $attachment = shift;
SendMail( Server => $g_Server,
From => $g_From,
To => $g_To,
Subject => $subject,
Message => $message,
Attachment => $attachment );
}
1;