Skip to content

Commit

Permalink
use Email::Send to actually... sends the push log by mail
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Sukrieh committed Jul 16, 2009
1 parent 97bbed2 commit d5d7cbc
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions github.cgi
Expand Up @@ -6,8 +6,17 @@ use CGI;
use JSON;
use Data::Dumper;

use Email::Send;

use constant HAPPY_MESSAGE => 'Hello there, thanks for passing by!';
use constant UNHAPPY_MESSAGE => 'You go away nasty web monster!';
use constant FAILED_MESSAGE => 'Ooops, I failed sending an email to teh w0rld';

my $sender = 'sukria+github-webhook@sukria.net';
my $recipient = 'sukria@sukria.net';
my $smtp_host = 'private.sukria.net';

my $version = '0.1';

my $cgi = CGI->new;
print $cgi->header('text/plain');
Expand Down Expand Up @@ -38,11 +47,26 @@ foreach my $c (@$commits) {
$commits_str .= $c->{timestamp}.' - '.$c->{author}{name}."\n\n";
$commits_str .= " * ".$c->{message}."\n\n";
$commits_str .= $c->{url}."\n\n";
# $commits_str .= '-' x 79;
# $commits_str .= "\n\n";
}

print "$subject\n";
print '-' x 79, "\n";
print "$commits_str";
print "$footer\n";
my $content = "$subject\n"
. '-' x 79
. "\n"
. "$commits_str"
. "$footer\n";

my $message = "To: $recipient\n"
. "From: $sender\n"
. "X-Mailer: github-webhook-perl $version\n"
. "X-github-project: ".$repo->{name}."\n"
. "Subject: $subject\n\n"
. $content;

my $email = Email::Send->new({mailer => 'SMTP'});
$email->mailer_args([Host => $smtp_host]);
if($email->send($message)) {
print HAPPY_MESSAGE;
}
else {
print FAILED_MESSAGE;
}

0 comments on commit d5d7cbc

Please sign in to comment.