use Net::SMTP;
use MIME::Lite;
my $DESTINATION = '3.3.3.3';
my $DOMAIN1 = "pc1.com";
my $DOMAIN2 = "pc2.com";
my $MAIL_USR1 = 'test001';
my $PSW1 = 'test001';
my $MAIL_USR2 = 'test002';
my $PSW2 = 'test002';
my $mail_from = $MAIL_USR1."@".$DOMAIN1;
my $mail_to = $MAIL_USR2."@".$DOMAIN2;
my $mail_subject = "SMTP test";
my $mail_attach = "/tmp/conf/klez.h.bin"; // 这个参数是给后面Path传的,必须写到文件名,不能只写到文件前面的路径部分,否则传过去只有文件名而没有文件内容。
my $attach_name = "klez.h.bin";
my $mail_content = $mail_subject;
$smtp = Net::SMTP->new(
$DESTINATION,
Port=>25,
Hello=>"pc1.com",
Debug=>1
);
die("smtp undefined: $@") if !defined $smtp;
#my $auth_return = $smtp->auth($MAIL_USR1,$PSW1);
#die("auth error: $@") if !defined $auth_return;
my $msg=MIME::Lite->new(
From => $mail_from,
To => $mail_to,
Subject => $mail_subject,
Data => $mail_content,);
$msg->attach(
Type => 'AUTO',
Path => $mail_attach,
Filename => $attach_name,);
my $content_string=$msg->as_string() or die "$!";
$smtp->mail($mail_from);
$smtp->to($mail_to);
$smtp->data();
$smtp->datasend($content_string);
$smtp->dataend();
$smtp->quit;
use MIME::Lite;
my $DESTINATION = '3.3.3.3';
my $DOMAIN1 = "pc1.com";
my $DOMAIN2 = "pc2.com";
my $MAIL_USR1 = 'test001';
my $PSW1 = 'test001';
my $MAIL_USR2 = 'test002';
my $PSW2 = 'test002';
my $mail_from = $MAIL_USR1."@".$DOMAIN1;
my $mail_to = $MAIL_USR2."@".$DOMAIN2;
my $mail_subject = "SMTP test";
my $mail_attach = "/tmp/conf/klez.h.bin"; // 这个参数是给后面Path传的,必须写到文件名,不能只写到文件前面的路径部分,否则传过去只有文件名而没有文件内容。
my $attach_name = "klez.h.bin";
my $mail_content = $mail_subject;
$smtp = Net::SMTP->new(
$DESTINATION,
Port=>25,
Hello=>"pc1.com",
Debug=>1
);
die("smtp undefined: $@") if !defined $smtp;
#my $auth_return = $smtp->auth($MAIL_USR1,$PSW1);
#die("auth error: $@") if !defined $auth_return;
my $msg=MIME::Lite->new(
From => $mail_from,
To => $mail_to,
Subject => $mail_subject,
Data => $mail_content,);
$msg->attach(
Type => 'AUTO',
Path => $mail_attach,
Filename => $attach_name,);
my $content_string=$msg->as_string() or die "$!";
$smtp->mail($mail_from);
$smtp->to($mail_to);
$smtp->data();
$smtp->datasend($content_string);
$smtp->dataend();
$smtp->quit;