send html email
( categories: network )You can easily send html emails from Perl using MIME::Lite; it's very simple, lightweight and gets the job done.
MIME::Lite is not included in a standard perl installation, so you have to install the module from CPAN using this command:
cpan -i MIME::Lite
Optionally, if you are on Debian, you can install it using apt-get:
apt-get install libmime-lite-perl
Here's some sample script:
sending mail with attachments
( categories: network )To send mail with attachments, create a multipart message using MIME::Lite module.
Example:
check whether a host is reachable through the network
( categories: network )Use the Net::Ping module:
#!/usr/bin/perl
use Net::Ping;
my $host = "192.168.0.1";
my $p = Net::Ping->new();
print "$host is reachable\n" if ( $p->ping($host) );
sending mail from a Perl script
( categories: network )There are many ways to send e-mails using Perl. One simple way is to use the module Mail::Send:
#!/usr/bin/perl
use Mail::Send;
$body = "This is the body of the message";
#-- initialize the object
$msg = new Mail::Send Subject=>'example subject', To=>'user1', Cc=>'user2@host';
#-- launch mailer and set headers
$fh = $msg->open;
#-- print the message body
print $fh "Hello,\n";
print $fh "$body\n";
#-- complete the message and send it
$fh->close;
connect to a ftp server
( categories: network )Use Net::FTP module. The functions are named like the corresponding ftp commands, so it's very easy to use.
Example:
