Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: How to send mail from Perl/Tk Program?

by Anonymous Monk
on Apr 13, 2007 at 06:39 UTC ( #609835=note: print w/replies, xml ) Need Help??

in reply to Re: How to send mail from Perl/Tk Program?
in thread How to send mail from Perl/Tk Program?

use strict; use Tk; use Tk::Animation; use Tk::LabEntry; use Tk::Dialog; use Net::SMTP; # main window my $mw = MainWindow->new(-title=>'SendMail Easy'); $mw->maxsize(qw/450 530/); $mw->minsize(qw/450 530/); my $fmain = $mw->Frame( -foreground=>'white',-background => 'ivory2', +-relief=> 'groove', -borderwidth=>2 )->pack( -side => 'top'); my $lbtop = $fmain->Label(-text => "SendMail Easy\n", -foreground => 'black', -background => 'ivory2')->pack(-side=>'top'); # from to my ($from, $to, $subj); my $fr1 = $fmain->Frame( -background => 'gray', -relief=> 'groove', -b +orderwidth=>2 )->pack( -side => 'top'); $fr1->LabEntry(-label=>'From:',-textvariable=>\$from,-labelPack=>[-sid +e=>'left'],-width=>30, -foreground => 'blue',-background => 'white')->pack(); $fr1->LabEntry(-label=>' To :',-textvariable=>\$to,-labelPack=>[-side +=>'left'],-width=>30, -foreground => 'blue',-background => 'white')->pack(); my $txtsubj = $fr1->LabEntry(-label=>'Subj:',-textvariable=>\$subj,-la +belPack=>[-side=>'left'],-width=>30, -foreground => 'blue',-background => 'white')->pack(); # ,-textvariable=>'' # compose my $fr2 = $fmain->Frame( -background => "ivory2", -relief => +'groove', -borderwidth=>2 )->pack( -side => 'top'); my $text = $fr2->Scrolled('Text', -scrollbars => 'osoe', -wrap => 'none', -foreground => 'blue', -background => 'white', -relief=>'flat')->pack(); # send button my $send = $fmain->Button( -text => 'Send eMail', -command => \&sendmail, -relief => 'groove', -foreground => 'black', -background => 'ivory2', )->pack(-ipadx=>10,-ipady=>5); $send->bind('<ButtonRelease-1>' => sub { $mw->messageBox(qw/-icon info -type OK -message/ => "eMail Sent... + \@njoy!"); }); # copyleft my $lbbottom = $mw->Label(-text => "Copyleft to Larry Wall", -foreground => 'black', -background => 'ivory2')->pack(-side=>'bottom'); ## animation my $camelanim = $mw->Animation('-format' => 'gif', -file => Tk->findINC('anim.gif') ); $mw->Label(-image => $camelanim)->pack(-side=>'bottom'); $camelanim->start_animation(200); MainLoop; sub sendmail{ my @message = $text-> get('1.0', 'end'); my $subject = $txtsubj -> get('1.0', 'end'); eval { my $cc = ''; my $smtp = Net::SMTP->new('smtp.server', Debug => 1) or die "connect"; $smtp->mail($from) or die "mail"; $smtp->to($to) or die "to"; # $smtp->to($cc) or die "cc"; $smtp->to($cc) or die "cc"; $smtp->data() or die "data"; $smtp->datasend($subject) or die "subject"; foreach my $line (@message) { $smtp->datasend("$line\n") or die "datasend"; } $smtp->dataend() or die "dataend"; $smtp->quit() or die "quit"; }; if ($@) { die "Message not sent: $@ failed\n"; } }

Replies are listed 'Best First'.
Re^3: How to send mail from Perl/Tk Program?
by mikasue (Friar) on Apr 18, 2007 at 12:36 UTC
    This did not work for me. I got the following error.
    Tk::Error: wrong # args: should be ".frame.frame.labentry2.entry get" +at F:/Perl /lib/ line 252. Tk callback for .frame.frame.labentry2.entry Tk::__ANON__ at F:/Perl/lib/ line 252 Tk::Derived::Delegate at F:/Perl/lib/Tk/ line 469 Tk::Widget::__ANON__ at F:/Perl/lib/Tk/ line 322 main::sendmail at f:\BPP4kids\ line 63 Tk callback for .frame.button Tk::__ANON__ at F:/Perl/lib/ line 252 Tk::Button::butUp at F:/Perl/lib/Tk/ line 111 <ButtonRelease-1> (command bound to event)

    All is not lost from the post though. I did learned how to include an animated gif in my program. Thanks!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://609835]
[marto]: they have a commercial product called perlapp
[mark4]: Do you h=know how I can get pp.exe? Is there a module I can install that includes this?
[marto]: I always found Strawberry Perl on windows to be a much better environment, made life much easier
[marto]: pp. install it like you would any other module
[marto]: it probably exists in one of the PPM repositories
[marto]: failing that see the README
[mark4]: I installed "PAR" from the ppm install window. pp.exe. did not show up.
[marto]: it should just be a script, pp, or on windows pp.bat, post install you should just be able to call pp -x packed.exe as the PPM package should put everything required into the appropriate path

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2018-01-19 14:15 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (218 votes). Check out past polls.