Important alert: (current site time 7/15/2013 8:46:02 PM EDT)
 

VB icon

Email Client in Tk

Email
Submitted on: 6/1/2004 9:37:59 AM
By: Damian myerscough  
Level: Intermediate
User Rating: By 1 Users
Compatibility: 5.0 (all versions), Active Perl specific, 4.0 (all versions), 3.0 (all versions), Pre 3.0
Views: 9301
 
     Send Emails with attachments

 
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: Email Client in Tk
= Description:Send Emails with attachments
= By: Damian myerscough
=
= Inputs:To
From
Subject
Message
Attachment
=
= Returns:Sends an email with an attachment
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=588&lngWId=6=for details.=**************************************

#!/usr/bin/perl -w
#
# [*] Email Client with Attachment capability
# [*] Coded By; Damian Myerscough
# [*] 0xSoftware Inc
#
use Tk;
use Tk::Dialog;
require Tk::LabFrame;
##################################
# Create Main window
#################################
$Windows = MainWindow->new;
$Windows->title("0xSoftware Inc Email Client");
$Windows->geometry("500x500");
$Windows->configure(-background => "#33CCFF");
######################################
# Creates Lables and text entrys and
# places them on the window
######################################
my $ToForm = $Windows->LabFrame(-borderwidth => '1',
-background => "#33CCFF",
-label=> "To:",
-labelside=> "acrosstop",
-relief => 'flat');
$ToForm->pack;
my $FromForm = $Windows->LabFrame(-borderwidth => '1',
 -background => "#33CCFF",
 -label=> "From:",
 -labelside=> "acrosstop",
 -relief => 'flat');
$FromForm->pack;
my $SubjectForm = $Windows->LabFrame(-borderwidth => '1',
 -background => "#33CCFF",
 -label=> "Subject:",
 -labelside=> "acrosstop",
 -relief => 'flat');
$SubjectForm->pack;
my $MessageForm = $Windows->LabFrame(-borderwidth => '1',
 -background => "#33CCFF",
 -label=> "Message:",
 -labelside=> "acrosstop",
 -relief => "flat");
$MessageForm->pack;
my $AttachmentsForm = $Windows->LabFrame(-borderwidth => '1',
 -background => "#33CCFF",
 -label=> "Attachments:",
 -labelside=> "acrosstop",
 -relief => "flat");
$AttachmentsForm->pack;
my $To = $ToForm->Entry(-cursor => "",
-font=> "Tahoma 8 normal",
-justify => "left");
$To->pack;
my $From = $FromForm->Entry(-cursor=> "",
-font => "Tahoma 8 normal",
-justify=> "left");
$From->pack;
my $Subject = $SubjectForm->Entry(-cursor=> "",
 -font => "Tahoma 8 normal",
 -justify=> "left");
$Subject->pack;
my $Message = $MessageForm->Text(-borderwidth => '1',
 -font=> "Tahoma 8 normal",
 -relief => "solid");
$Message->pack;
my $Attachments = $AttachmentsForm->Entry(-cursor=> "",
 -font => "Tahoma 8 normal",
 -justify => "left");
$Attachments->pack;
#####################################
# Start to place the Text boxes and
# labels into their correct places
#####################################
$ToForm->place(-width => 490,
-height => 100,
-x => 1,
-y => 3);
$To->place(-width => 450,
-height => 17,
-x => 10,
-y => 2);
$FromForm->place(-width => 490,
 -height => 324,
 -x => 3,
 -y => 50); 
$From->place(-width => 450,
 -height => 17,
 -x => 10,
 -y => 2);
$SubjectForm->place(-width => 490,
-height => 374,
-x => 3,
-y => 100);
$Subject->place(-width => 450,
-height => 17,
-x => 10,
-y => 2);
$MessageForm->place(-width => 490,
-height => 200,
-x => 3,
-y => 150);
$Message->place(-width => 450,
-height => 150,
-x => 10,
-y => 3);
$AttachmentsForm->place(-width => 490,
-height => 375,
-x => 7,
-y => 330);
$Attachments->place(-width => 450,
-height => 17,
-x => 7,
-y => 2); 
###################################
# Create Send and exit buttons
###################################
my $Send = $Windows->Button(-activebackground => "#FFFCBF", 
-activeforeground => "#0000FF", 
-background=> "#33CCFF", 
-borderwidth => 1, 
-text => "Send Email",
-command => sub{ SendEMail() }, 
-cursor=> "", 
-font => "Tahoma 8 bold", 
-foreground=> "#140F7B", 
-relief=> "solid"
);
my $Exit = $Windows->Button(-activebackground => "#FFFCBF",
-activeforeground => "#0000FF",
-background=> "#33CCFF",
-borderwidth => 1,
-text => "Exit",
-command => sub{ &Exit },
-cursor=> "",
-font => "Tahoma 8 bold",
-foreground=> "#140F7B",
-relief=> "solid"
);
my $Clear = $Windows->Button(-activebackground => "#FFFCBF",
 -activeforeground => "#0000FF",
 -background=> "#33CCFF",
 -borderwidth => 1,
 -text => "Clear",
 -command => sub{ &Clean },
 -cursor=> "",
 -font => "Tahoma 8 bold",
 -foreground=> "#140F7B",
 -relief=> "solid"
);
$Send->pack;
$Exit->pack;
$Clear->pack;
#######################################
# Place buttons on the screen at a 
# certain coordinate
######################################
$Send->place(-width => 100,
 -height => 20,
 -x => 15,
 -y => 380);
$Exit->place(-width => 100,
 -height => 20,
 -x => 120,
 -y => 380);
$Clear->place(-width => 100,
 -height => 20,
 -x => 225,
 -y => 380); 
sub SendEMail()
{
 ####################################
 # Collect the users information
 ####################################
 my $EmailTo = $To->get;
 my $EmailFrom = $From->get;
 my $EmailSubject = $Subject->get;
 my $EmailMessage = $Message->get('1.0', 'end');;
 my $EmailAttachments = $Attachments->get;
 if(($EmailTo) && ($EmailFrom) && ($EmailSubject) && ($EmailMessage) && ($EmailAttachments))
 {
print"All Data has been inputted correctly\n";
$Sender = new Mail::Sender{ smtp => 'mail.smtpserver.com',
from => "$EmailFrom"
 };
##############################
# Email Configuration
############################## 
$Sender->MailFile({to => "$EmailTo",
 from=> "$EmailFrom",
 subject => "$EmailSubject",
 msg => "$EmailMessage",
 file=> "$EmailAttachments"});
#############################
# Create a DialogBox 
#############################
$DialogBox = $Windows->Dialog(-title=> "Email Sent Sucesfully: $EmailTo",
 -text=> "The email was sucessfuly sent to: $EmailTo",
 -buttons => ["OK"]);
$DialogBox->Show();
 
 }elsif(($EmailTo) && ($EmailFrom) && ($EmailSubject) && ($EmailMessage))
 {
 $Sender = new Mail::Sender{ smtp => 'mail.smtpserver.com',
from => "$EmailFrom"
 };
##############################
# Email Configuration
##############################
$Sender->MailMsg({to => "$EmailTo",
 from=> "$EmailFrom",
 subject => "$EmailSubject",
 msg => "$EmailMessage"
});
#############################
# Create a DialogBox
#############################
$DialogBox = $Windows->Dialog(-title=> "Email Sent Sucesfully: $EmailTo",
 -text=> "The email was sucessfuly sent to: $EmailTo",
 -buttons => ["OK"]);
$DialogBox->Show();
 
 }else{
 $DialogBox = $Windows->Dialog(-title=> "Error",
-text=> "Error Field Missing ",
-buttons => ["OK"]);
 
 $DialogBox->Show();
 
 } 
}
sub Exit()
{
 $DialogBox = $Windows->Dialog(-title=> "0xSoftware Inc",
-text=> "This Email Client was coded By: Damian Myerscough ",
-buttons => ["OK"]);
 $DialogBox->Show();
 exit;
}
sub Clean()
{
 $Attachments->delete(0, 'end');
 $Subject->delete(0, 'end');
 $From->delete(0, 'end');
 $To->delete(0, 'end'); 
}
MainLoop;


Other 35 submission(s) by this author

 


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 Intermediate 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


 There are no comments on this submission.
 

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.