Perl Net::SMTP发送电子邮件

(0 comments)

测试阶段建议加上参数Debug => 1打开调试信息,到正式使用再关闭这个选项。

#! /usr/bin/perl -w
 
use Net::SMTP;
 
my $mailhost = "smtp.liaojl.com";
my $mailfrom = 'liaojl@liaojl.com';
# the recipient list
my @mailto = ('liaojl@liaojl.com', 'administrator@liaojl.com');
my $subject = "My Subject";
my $text = "The first line.\nThe second line.";
 
$smtp = Net::SMTP->new($mailhost, Hello => 'localhost', Timeout => 120, Debug => 1);
# auth login, type your user name and password here
# $smtp->auth('user','pass');
 
foreach my $mailto (@mailto) {
    # Send the From and Recipient for the mail servers that require it
    $smtp->mail($mailfrom);
    $smtp->to($mailto);
 
    # Start the mail
    $smtp->data();
 
    # Send the header
    $smtp->datasend("To: $mailto\n");
    $smtp->datasend("From: $mailfrom\n");
    $smtp->datasend("Subject: $subject\n");
    $smtp->datasend("\n");
 
    # Send the message
    $smtp->datasend("$text\n\n");
 
    # Send the termination string
    $smtp->dataend();
}
 
$smtp->quit;

Currently unrated

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required