use strict;
use warnings FATAL => 'all';
use MIME::Lite;
use Tk;
use List::Util qw/min max/;
my $toAddr = 'keeper.of.the.time@your.domain.com';
my $fromAddr = 'wibble@your.domain.com';
my $bccAddr = 'wibble@your.domain.com';
my $subject = 'Time today';
my $timeSheet;
my $inFile;
if (open $inFile, "< MailTime.txt")
{
$toAddr = <$inFile>;
chomp $toAddr if $toAddr;
$fromAddr = <$inFile>;
chomp $fromAddr if $fromAddr;
$bccAddr = <$inFile>;
chomp $bccAddr if $bccAddr;
$subject = <$inFile>;
chomp $subject if $subject;
$timeSheet .= $_ while <$inFile>;
close $inFile;
}
defined $timeSheet or $timeSheet = "This\n7\tBug Fixing\n\nOther\n2\tT
+he other\n";
my $main = MainWindow->new (-title => "Time Sheet From $fromAddr to $t
+oAddr");
my $toLabel = $main->Label (-text => 'Send to:')->form (-left => '%0')
+;
my $toEntry = $main->Entry (-textvariable => \$toAddr);
my $fromLabel = $main->Label (-text => 'From:')->form (-left => '%0',
+-top => $toLabel);
my $fromEntry = $main->Entry (-textvariable => \$fromAddr);
my $bccLabel = $main->Label (-text => 'Bcc:')->form (-left => '%0', -t
+op => $fromLabel);
my $bccEntry = $main->Entry (-textvariable => \$bccAddr);
my $subjectLabel = $main->Label (-text => 'Subject:')->form (-left =>
+'%0', -top => $bccLabel);
my $subjectEntry = $main->Entry (-textvariable => \$subject);
my $text = $main->Text();
my $maxWidth = max
(
$toLabel->reqwidth (), $fromLabel->reqwidth (),
$bccLabel->reqwidth (), $subjectLabel->reqwidth ()
);
$toEntry->form (-left => ['%0', $maxWidth + 5], -right => '%100');
$fromEntry->form (-left => ['%0', $maxWidth + 5], -right => '%100', -t
+op => $toEntry);
$bccEntry->form (-left => ['%0', $maxWidth + 5], -right => '%100', -to
+p => $fromEntry);
$subjectEntry->form (-left => ['%0', $maxWidth + 5], -right => '%100',
+ -top => $bccEntry);
$text->insert ('end', $timeSheet);
my $cancel = $main->Button (-text => "Cancel", -command => sub {exit (
+1);})
->form (-left => '%10', -ls => 20, -bottom => '%100');
my $save = $main->Button
(
-text => "Save",
-command => sub
{
$timeSheet = $text->Contents();
save ();
}
)
->form (-right => '%90', -rs => 20, -bottom => '%100');
my $send = $main->Button (-text => "Send", -command => \&doSend);
$send->form (-left => $cancel, -right => $save, -ls => 1, -rs => 1, -b
+ottom => '%100');
$text->form
(
-left => '%0', -right => '%100',
-top => $subjectEntry, -bottom => $send,
-pady => 5
);
MainLoop ();
save ();
sub doSend
{
$timeSheet = $text->Contents();
$main->destroy();
my $msg = MIME::Lite->new
(
From => $fromAddr,
Bcc => $bccAddr,
To => $toAddr,
Data => $timeSheet,
Subject => $subject
);
MIME::Lite->send ("smtp", "smtp.your.domain.com");
$msg->send;
}
sub save
{
my $outFile;
open $outFile, "> MailTime.txt" or die "Failed to create MailTime.txt:
+ $!\n";
print $outFile "$toAddr\n$fromAddr\n$bccAddr\n$subject\n";
print $outFile $timeSheet;
close $outFile;
}
|