renran421 发表于 2018-8-31 10:36:10

一个用perl写的发邮件的脚本

  #!/usr/bin/perl
  =pod
  #send email common script
  #Angelo - 2008/10/06
  ttachment]
  #EmailServer - emailserver.
  #port - listening port, default is 25
  uard.com.set "" if no to-sendee
  uard.com.set "" if no cc-sendee
  #Subject   - subject of your email,string.set "" if no subject.
  r.
  #Attachment- full path of attachement,seperated by ",".
  # Revision History
  # Will Yi - 2011/12/30 - Added a command line argument to specify the debug level for send()
  =cut
  use MIME::Lite;
  use strict;
  #my $reportserver = 'ex01bd.bdc.wgti.net';
  #my $port = '25';
  #my $fromaddress= 'local.test';
  #my $reporttoaddress = 'angelo.liu@watchguard.com';
  if ((scalar @ARGV) < 5 || (scalar @ARGV) > 9) {
  &usage;
  exit -1;
  }
  my $reportserver = $ARGV;
  my $port = $ARGV;
  my $fromaddress= $ARGV;
  my $reporttoaddress = $ARGV;
  my $encode_type = $ARGV;
  if ((scalar @ARGV) < 5 || (scalar @ARGV) > 9) {
  &usage;
  exit -1;
  if ((scalar @ARGV) < 5 || (scalar @ARGV) > 9) {
  &usage;
  exit -1;
  my $subject = 'automation_test';
  my $body = 'automation test';
  my $attachment = '';
  my @attachlist;
  if ($ARGV) {
  $subject = $ARGV;
  if ($ARGV) {
  $subject = $ARGV;
  }
  if ($ARGV) {
  $subject = $ARGV;
  }
  $body = $ARGV;
  if ($ARGV) {
  $body = $ARGV;
  if ($ARGV) {
  $body = $ARGV;
  }
  if ($ARGV) {
  $attachment = $ARGV;
  if ($ARGV) {
  $attachment = $ARGV;
  if ($ARGV) {
  $attachment = $ARGV;
  }
  if ($ARGV) {
  $debug_level = $ARGV; # 0-disable; 1-verbose
  if ($ARGV) {
  $debug_level = $ARGV; # 0-disable; 1-verbose
  }
  if ($ARGV) {
  $debug_level = $ARGV; # 0-disable; 1-verbose
  if (!($attachment eq '')) {
  @attachlist = split(',',$attachment);
  foreach my $eachattach (@attachlist) {
  -e $eachattach or die &quot;$eachattach doesn't exists.\n&quot;;
  }
  }
  }
  my $msg = MIME::Lite->new(
  From   => $fromaddress,
  To       => $reporttoaddress,
  Subject=> $subject,
  Type   => 'multipart/mixed',
  Encoding => $encode_type,
  );
  );
  $msg->attach(
  #Type      => 'AUTO',
  Data      => $body,
  $msg->attach(
  #Type      => 'AUTO',
  Data      => $body,
  );
  $msg->attach(
  #Type      => 'AUTO',
  Data      => $body,
  );
  if (!($attachment eq '')) {
  foreach my $eachattach (@attachlist) {
  $msg->attach(
  Path      => $eachattach,
  Type            => 'AUTO',
  Disposition => 'attachment'
  );
  }
  }
  }
  $msg->send('smtp',$reportserver, Debug=>$debug_level, Port => $port);
  .\n&quot;;
  print &quot;EmailServer\t- emailserver address.\n&quot;;
  d.com,yyy\@watchguard.com.set \&quot;\&quot; if no to-sendee.\n&quot;;
  print &quot;EncodeType\t- should be 7bit/8bit/binary\n&quot;;
  st one char.\n&quot;;
  t, default is 1\n&quot;;
  return 0;
  使用方法如下:automation@net1PC1:~$ perl send_common_email.pl ?
  Usage: send_common_email.pl       .
  eg. send_common_email.pl ex01bd.bdc.wgti.net fromme@xx.com,xxx@xx.com,yyy@xx.com.
  EmailServer   - emailserver address.
  FromAddress   - &quot;From&quot; address
  ToAddress       - &quot;to&quot; address,seperated by &quot;,&quot; if you have muti-sendee,eg: xxx@xx.com,yyy@xx.com.set &quot;&quot; if no to-sendee.
  EncodeType      - should be 7bit/8bit/binary
  Subject         - subject of your email,string.set &quot;&quot; if no subject.
  Body            - context of your email,it can be a string or a exist-file.can not be &quot;&quot;.at least one char.
  Attachment      - full path of attachement,seperated by &quot;,&quot;.
  DebugLevel      - Set the debug level when sending mail. Value 1-verbose,0-disable. If not set, default is 1

页: [1]
查看完整版本: 一个用perl写的发邮件的脚本