IT Community - Software Programming, Web Development and Technical Support

Simple Email - Using Perl

This is a discussion on Simple Email - Using Perl within the Perl forums, part of the Software Development category; hi, simple email function : #!/usr/bin/perl print "Content-type: text/html\n\n"; # Simple Email Function # ($to, $...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Perl

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 07-18-2007, 12:11 AM
raj raj is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
raj is on a distinguished road
Default Simple Email - Using Perl

hi,

simple email function :

#!/usr/bin/perl
print "Content-type: text/html\n\n";

# Simple Email Function
# ($to, $from, $subject, $message)
sub sendEmail
{
my ($to, $from, $subject, $message) = @_;
my $sendmail = '/usr/lib/sendmail';
open(MAIL, "|$sendmail -oi -t");
print MAIL "From: $from\n";
print MAIL "To: $to\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message\n";
close(MAIL);
}

sendEmail("ToID\@domain.com", "FromID\@domain.com", "Simple email.", "This is a test of the email function.");
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 07-18-2007, 12:25 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 385
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: Simple Email - Using Perl

Can we know how to send attachments in the mail?
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 07-18-2007, 02:22 AM
raj raj is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
raj is on a distinguished road
Default Re: Simple Email Attachment- Using Perl

#!/usr/bin/perl

use MIME::Lite;
use Net::SMTP;

### Adjust sender, recipient and your SMTP mailhost
my $from_address = 'FromEmailID@domain.com';
my $to_address = 'ToEmailID@domain.com';
my $mail_host = 'mail.domain.com';

### Adjust subject and body message
my $subject = 'Testing - Perl mail with Attachment';
my $message_body = "Here's the attachment file(s) you wanted ";

### Adjust the filenames
my $my_file_gif = '1.gif';
my $your_file_gif = '2.gif';
# my $my_file_zip = '1.zip';
# my $your_file_zip = '2.zip';

### Create the multipart container
$msg = MIME::Lite->new (
From => $from_address,
To => $to_address,
Subject => $subject,
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

### Add the text message part
$msg->attach (
Type => 'TEXT',
Data => $message_body
) or die "Error adding the text message part: $!\n";

### Add the GIF file
$msg->attach (
Type => 'image/gif',
Path => $my_file_gif,
Filename => $your_file_gif,
Disposition => 'attachment'
) or die "Error adding $file_gif: $!\n";


### Send the Message
MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple program help... hkp819 C and C++ Programming 1 12-28-2008 07:38 AM
Simple URL Variable jennifergttfrd PHP Programming 0 12-27-2008 07:45 AM
Simple question for PHP thomasEpand PHP Programming 0 11-18-2008 10:42 PM
How to set Perl Interpreter within perl script sivaramakrishnan Perl 1 07-19-2007 05:45 AM
Create Simple ShoutBox spid4r PHP Programming 0 03-08-2007 10:03 PM


All times are GMT -7. The time now is 10:05 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0