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
  3 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-18-2007, 01: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
Sponsored Links
  #2 (permalink)  
Old 07-18-2007, 01:25 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
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 (permalink)  
Old 07-18-2007, 03: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 On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/perl/2096-simple-email-using-perl.html
Posted By For Type Date
domain email hosting - Simple Email - Using Perl This thread Refback 07-18-2007 09:34 AM
email domain hosting - Simple Email - Using Perl This thread Refback 07-18-2007 09:29 AM
email hosting - Simple Email - Using Perl This thread Refback 07-18-2007 09:28 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Interview Questions Sathish Kumar C# Programming 56 03-21-2008 07:53 AM
Simple Alexa Rank Retrieval Sabari PHP Programming 28 12-04-2007 06:44 AM
simple example for the java concepts lavanya Java Programming 2 07-20-2007 06:48 AM
How to set Perl Interpreter within perl script sivaramakrishnan Perl 1 07-19-2007 06:45 AM
Create Simple ShoutBox spid4r PHP Programming 0 03-08-2007 11:03 PM


All times are GMT -7. The time now is 02:34 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0