Script para enviar Email em Perl

#!/usr/bin/perl -w

use Data::Dumper;
use MIME::Lite;

if ( scalar @ARGV != 3 ) {
  print 'ERRO!!!! Faltando parametros!', $/, 'Use: ', $0, ' email_destino@mydomain.com assunto corpo_email', $/;
  print Dumper( @ARGV );
} else {
  print 'enviando email para: ', $ARGV[0], $/;
  envia_email(`hostname -s`, $ARGV[0], $ARGV[1], $ARGV[2]);
}

sub envia_email {
  local ($from, $to, $subject, $message) = @_;

  $email = MIME::Lite->new(
  From => $from,
  To => $to,
  Type => 'text/html',
  Subject => $from . ' ' . $subject,
  Data => $message
  );
  MIME::Lite->send('smtp', 'mail.,mydomain.com', DEBUG=>1);
  $email->send();
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s