Perl使用主机名发邮件

前端之家收集整理的这篇文章主要介绍了Perl使用主机名发邮件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用别的邮件系统有诸多限制,
​不如用linux系统本机的邮件功能

#!/usr/bin/perl
##
# Test linux mail
use warnings;
use strict;
use Mail::Mailer;
use Socket;

my $mail_subject = "test  mail";
my @daily_mail_content = "test  is ok!\n";
&mailer_send_mail($mail_subject,\@daily_mail_content);

sub mailer_send_mail {
  my ($subject,$param) = @_;
  my $message = join('',@$param);
  my $host = `hostname`;
  my $mail_host = 'root@'.$host;
  my $from_address = $mail_host;
  my $to_address = 'username@yyy.com';
  my $mailer = Mail::Mailer->new("sendmail");
  $mailer->open({From       => $from_address,
                               To          => $to_address,helvetica; line-height:18px">                               Subject => $subject,helvetica; line-height:18px">                               })
  or die "Can't open : $!\n";
  print $mailer $message;
  $mailer->close();
}

猜你在找的Perl相关文章