Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
email notification
10-03-2010, 12:55 PM,
Post: #1
email notification
Ada member yang PM masokis pasal menda ni. dah cari jumpa ni:
#!/usr/bin/perl -w
use strict;

use MIME::Lite; # needed only if sending attachments
use Net::SMTP;

my $path = "c:/somefolder/excel.xls"; # full path to whatever you want to attach
my $file = substr($path,rindex($path,"/")+1); # isolate just file name from full path

# Set sender, recipient & SMTP mailhost
my $from_address = "sender\@some.domain";
my $to_address = "recipient\@some.domain";
my $mail_host = "mail.some.domain";

# Subject & body of the message
my $subject = "Subject of the mail message";
my $message_body = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, ";
$message_body.="quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat ";
$message_body.="nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

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

# Insert message body
$msg->attach (
Type => "TEXT",
Data => $message_body
) or die "Mail> Napaka pri dodajanju sporocila: $!\n";

# Add attachment (delete if you don't need it)

$msg->attach (
Type => "application/", # In type you should put correct mime type for the attached file
Path => $path,
Filename => $file,
Disposition => "attachment"
) or die "Error while attaching $file: $!\n";

MIME::Lite->send("smtp", $mail_host, Timeout=>60);

Quote:#!/usr/bin/perl -w

use strict;
use warnings;
use Carp;
# Perhaps the most common method is by opening a filehandle pipe to sendmail
# this method is published many places,O'rielly Perl Cookbooks
# (i think just about every perl book out there does this same thing,
# so altho you CAN pipe to sendmail.

# Open Filehandle "MAIL", pipe the output to the shell command sendmail
# with the arguement -t, which tells sendmail to extract recipients from
# message headers, (this assumes that you are using postfix mail server
# (if u have postfix you dont have to define any command line mail recipeints).
my $receive = '';
my $sender = '';
my $subject = 'What to say what to say...';

my $message = <<"EOF";
To: $receive
From: $sender
Subject: $subject

Hello, World!

my $sendmail = '/usr/sbin/sendmail -t';
open my $mail_fh,'|', $sendmail
or croak 'Could not open pipe to sendmail';
print $mail_fh << $message;
close $mail_fh;

# you could do something
# very similar using the mailx command

my $message_2 = 'Message';
my $mailx = '/usr/sbin/mailx -s $subject $receive';
open my $mail_fh2,'|', $mailx
or croak 'Could not open pipe to sendmail';
print $mail_fh2 << $message_2;
close $mail_fh2;

# Another way you can do it is via the Mail::Sendmail CPAN module
# you would have ot install the moudle through ppm just so u know
use Mail::Sendmail;

%mail_sendmail = ( To => $receive,
From => $sender,
Subject => $subject,
Message => "Some Message to people"
if (sendmail %mail_sendmail) {
print "Mail sent correctly.\n"
print "Error: %mail_sendmail::Sendmail::error \n"

Possibly Related Threads...
Thread Author Replies Views Last Post
  Anonymous Email Send XShimeX 3 1,505 19-05-2013, 07:47 PM
Last Post: RFC792
  Email/URL Ripper XShimeX 0 404 16-02-2009, 09:37 AM
Last Post: XShimeX

Forum Jump: