How do I send e-mail with Perl Script ?
Here is a sample for sending e-mail with PERL scripts.
use strict;
use Net::SMTP;
my $message = "From: sender\@domain.com\nTo:
receiver\@domainTo.com\nSubject: Hello World\n\nTest\n\n";
print "Message:\n";
print $message;
print "\n";
my $DEBUG = 1;
my $ServerName = "smtp.domain.com";
my $ServerAccount = "****\@domain.com";
my $ServerPwd = "********";
my $MailFrom = "sender\@domain.com";
my $MailTo = "receiver\@domainTo.com";
print "Server variables assigned\n";
my $smtp = Net::SMTP->new($ServerName, Hello => "domain.com", Debug => 1);
die "Couldn't connect to server" unless $smtp;
print "Server connection opened\n";
if ( !$smtp->auth($ServerAccount, $ServerPwd) ) {
print "authentication failed or not needed\n";
}
if ( !$smtp->mail( $MailFrom ) ) {
print "sender not accepted\n";
exit 1;
}
if (!$smtp->to( $MailTo ) ) {
print "addressee not accepted\n";
exit 1;
}
print "Server variables checked\n";
my $maildata = $message;
$smtp->data();
$smtp->datasend( $maildata );
$smtp->dataend();
$smtp->quit();
$smtp->quit;
print "Finished sending email\n";
Add Your Comments