Subversion Repositories PEEPS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
package PEEPSMailer;
2
 
3
use strict;
4
use Exporter 'import';
5
use Net::SMTPS;
6
use Email::Simple;
7
#use Email::MessageID;
8
 
9
our @EXPORT = qw( EmailUser );
10
 
11
my $server   = "smtp.gmail.com";
12
my $port     = 587;
13
my $user     = 'peeps@wftda.com';
14
my $password = 'pmrpegrigryhavpe';
15
 
16
#warn "loaded PEEPSMailer...";
17
 
18
sub EmailUser {
19
	my $email = shift;
20
	my $subject = shift;
21
	my $body = shift;
22
 
23
	my $dev = $ENV{SERVER_NAME} eq "peeps.wftda.com" ? "" : '[DEV] ';
24
 
25
  if ($body !~ /^<p>/i) {
26
    use HTML::Tiny;
27
    my $h = HTML::Tiny->new( mode => 'html' );
28
 
29
    $body = $h->p (split "\n", $body);
30
  }
31
 
32
#warn "DEBUG: Emailing $email...";
33
 
34
## the rollercon mail server's cert doesn't match it's name. (the first block ignores any mismatching name)
35
#  IO::Socket::SSL::set_defaults (
36
#    SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
37
#  );
38
#  IO::Socket::SSL::set_client_defaults(
39
#    SSL_verifycn_name => 'p3plmcpnl496538.prod.phx3.secureserver.net',
40
#  );
41
  IO::Socket::SSL::set_client_defaults(
42
    SSL_verifycn_name => 'smtp.gmail.com',
43
  );
44
 
45
  my $smtp = Net::SMTPS->new(
46
    $server,
47
    Hello => 'gmail.com',
48
    Port => $port,
49
    doSSL => 'starttls',
50
    Timeout => 15,
51
    Debug => 0
52
  );
53
  die "Could not connect to SMTP server!" unless $smtp;
54
 
55
	my $msg = Email::Simple->create(
56
	  header => [
57
	    To             => $email,
58
#	    Bcc            => $user,
59
	    From           => $user,
60
	    Subject        => $dev.$subject,
61
#	    'Message-Id'   => Email::MessageID->new->in_brackets,
62
	    'Content-type' => 'text/html',
63
    ],
64
	  body => $body,
65
	);
66
 
67
  $smtp->auth ($user, $password);
68
  $smtp->mail ($user);
69
  $smtp->to ($email);
70
#  $smtp->bcc ($user);
71
  $smtp->data ();
72
  $smtp->datasend ($msg->as_string);
73
  $smtp->quit;
74
 
75
}
76
 
77
 
78
1;