Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Light weight timesheet mailer

by GrandFather (Saint)
on Aug 16, 2005 at 23:33 UTC ( [id://484276]=sourcecode: print w/replies, xml ) Need Help??
Category: E-Mail Programs
Author/Contact Info peter@adi.co.nz
Description:

Light weight Tk and MIME::Lite based email program designed initially for sending daily time sheets that vary little from day to day.

Uses TK:form to lay out controls and manage resizing when the main window is resized.

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;
}
Replies are listed 'Best First'.
Re: Light weight timesheet mailer
by zentara (Archbishop) on Aug 17, 2005 at 12:21 UTC
    Nice example of using "form". Something new for me. :-)

    I'm not really a human, but I play one on earth. flash japh

      That was a lot of why I posted it. Maybe I should have put it in CUFP though?


      Perl is Huffman encoded by design.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://484276]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-20 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found