好久不用perl脚本写东西了,今天突发奇想,需要自动发送带附件的邮件,网上找了很多资料,修改了一下,就是这样了,先用ppm安装MIME::Lite和Authen::SASL包

#!/usr/bin/perl -w
use strict;
use warnings;
use MIME::Lite;
use MIME::Base64;
use Authen::SASL;
 
  my $from = '发件人邮箱';
  my $passwd = '发件人邮箱密码';
  my $to = '收件人邮箱';
  my $subject = "标题"
  my $content = "正文内容";
  my $fileone = 'z:\\123.png';
  my $filetwo = 'z:\\456.png';
  my $msg = MIME::Lite->new(
      From     =>  $from,
      To       =>  $to,
      Subject  =>  $subject,
      Type     =>  'TEXT',
      Data     =>  $content,
  );
  $msg->attach (
   Type        => 'AUTO',
   Path        => $fileone,
   Filename    => "1111.png",
   Disposition => 'attachment'
   ) or die "Error adding $fileone: $!\n";
   $msg->attach (
   Type        => 'AUTO',
   Path        => $filetwo,
   Filename    => "2222.png",
   Disposition => 'attachment'
   ) or die "Error adding $filetwo: $!\n";
  
  
  MIME::Lite->send('smtp','smtp邮箱服务器',
      Debug   =>'0',
      AuthUser=>$from,
      AuthPass=>$passwd,
  );
  $msg->send;