Important alert: (current site time 7/15/2013 9:17:56 PM EDT)
 

VB icon

mailer.zip

Email
Submitted on: 3/31/2002 7:33:29 PM
By: francesco gasparetto 
Level: Beginner
User Rating: Unrated
Compatibility: 5.0 (all versions)
Views: 10409
 
     The script acts as a smtp client. It allows the user to send e-mail. Good if you're new with Perl/tk. Show how to use the following Perl packages: Mail::sender Tk::FileDialog Tk::DialogBox
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: mailer.zip
= Description:The script acts as a smtp client. It allows the user to send e-mail. Good if you're new with Perl/tk. Show how to use the following Perl packages:
Mail::sender
Tk::FileDialog
Tk::DialogBox
= By: francesco gasparetto
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=304&lngWId=6=for details.=**************************************

use Tk;
use Tk::FileDialog;
use Tk::DialogBox;
use Mail::Sender;
my $templ_directory = "templates";
## creo la finestra
my $mw = new MainWindow;
$mw->configure(-title=>'The smtp client');
$mw->Label(-text => 'To:',)->pack;
$e = $mw->Entry(-textvariable => \$to)->pack;
$mw->Label(-text => 'Subject:', )->pack;
$e = $mw->Entry(-textvariable => \$subj)->pack;
$f = $mw->Frame->pack(-side => 'top', -fill => 'x');
 $mw->Label(-textvariable => \$infoalleg, -relief => 'ridge')-> ## barra di stato
 pack(-side => 'bottom', -fill => 'x');
## area testo
$t = $mw->Scrolled("Text")->pack(-side => 'bottom',
 -fill => 'both', -expand => 1);
$t->configure(-font => 'Tk::Font=SCALAR(0x234d8d8)'); ## ingrandisco la font di default
## bottone "invia"
$f->Button(-text => "Send", -command => \&invia_mail)->
 pack(-side => 'right', -anchor => 'e');
## bottone "Allega"
$f->Button(-text => "Attachment", -command => \&allega_file)->
 pack(-side => 'right', -anchor => 'e');
## bottone "Opzioni"
$f->Button(-text => "Options", -command => \&options_win)->
 pack(-side => 'left', -anchor => 'e');
## bottone "About"
$f->Button(-text => "About", -command => \&about_win)->
 pack(-side => 'left', -anchor => 'e');
get_profile();## inizializzo $smtp e $email
MainLoop;
sub get_profile### inizializzo le variabili $email e $smtp dal file 'info' per la comunicazione con il server --------------------------------------
{
		if (open(FH,'info.txt'))
		{
			while(<FH>)
			{
				($key,$value) = split(/=/,$_);
				if ($key eq 'email')
				{
					chomp($value);
					$email = $value;
					next;
				}
				if ($key eq 'smtp')
				{
					chomp($value);
					$smtp = $value;
					next;
				}
			}
		}
		else
		{
			$email = "";
			$smtp = "";
			$mw->withdraw();
			options_win();
		}
}
sub allega_file
{
 $fname = $mw->getOpenFile;
 if (!open(FH, "$fname"))
 {
	return;
 }
$infoalleg = "ALLEGATO: $fname";
close (FH);
}
sub invia_mail ## invio email
{
		$_ = $to;
		if ($to eq "" || !(/\./) || !(/@/))
		{
			$dlgbox = $mw->DialogBox(-title=>'Error');
		$dlgbox->add('label', "You have to fill the \"to:\" field correctly");
		$dlgbox->Show;
		return;
		}
		$sender = new Mail::Sender {smtp => $smtp, from => $email};
		if($fname eq "" || (!open(FH,$fname)) )		## nessun allegato
		{
			$sender->MailMsg({to => $to, subject => $subj, msg => $t->get("1.0", "end")});
		}
		else										## c'é l'allegato
		{
			$sender->MailFile({to => $to,
 							subject => $subj,
 							msg => $t->get("1.0","end"),
 							file => $fname});
 		}
}
sub options_win		## finestra delle opzioni
{
		$optwin = $mw->Toplevel(-relief=>'raised', -borderwidth=>5);
			$optwin->title("Configuration");
			$optwin->geometry('+300+300');
			$optwin->minsize( qw(250 100) );
		$optwin->Label(-text =>"Your profile\n\n")->pack(-side => 'top');
			$optwin->Label(-text =>'Your e-mail address')->pack(-side => 'top', -fill => 'x');
			$entry_email = $optwin->Entry(-textvariable => \$email)->pack(-side => 'top');
			$optwin->Label(-text =>"\nSmtp server address")->pack(-side => 'top', -fill => 'x');
			$entry_smtp = $optwin->Entry(-textvariable => \$smtp)->pack(-side => 'top');
			$optwin->Button(-text => "Save", -command => sub{&change_prof})->pack(-side=>'bottom');
}
sub change_prof		## salvo i cambiamenti dalla finestra di configurazione al file "info.txt"
{
		$_ = $email;
	if ($email eq "" || !(/\./) || !(/@/) )
	{
		$dlgbox = $mw->DialogBox(-title=>'Error');
		$dlgbox->add('label', 'Insert a correct e-mail address');
		$dlgbox->Show;
		return;
	}
	$_ = $smtp;
	if ($smtp eq "" || !(/\./) )
	{
		$dlgbox = $mw->DialogBox(-title=>'Error');
		$dlgbox->add('label', "Insert a correct smtp server address (ex: smtp.domain.com)");
		$dlgbox->Show;
		return;
	}
		open (FH, ">info.txt");
		print FH "email=$email\nsmtp=$smtp\n";
		close FH;
		$optwin->destroy;
		$mw->deiconify();
}
sub about_win
{
	my $about = $mw->Toplevel(-relief=>'raised', -borderwidth=>10);
			$about->title("About Me");
			$about->geometry('+300+300');
	my $label = $about->Label(-text=>"The Simple Mailer
By: Francesco Gasparetto
frenkolo\@yahoo.it
It acts as a smtp client
without any POP3 session, that means you
don\'t receive, you send. Shows how to use:
Mail::Sender
Tk::FileDialog
Tk::DialogBox");
$label->pack();
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
2/27/2003 1:42:54 PMserpent

nice 1

(If this comment was disrespectful, please report it.)

 
5/3/2004 10:19:42 AM

hello, i becam this error, sender.pm and filedialog.pm failed
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.