sendmail 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/perl
  2. ################################################################################
  3. # sendmail.pl
  4. # <rename this to /usr/sbin/sendmail for a FreeSWITCH
  5. # voicemail gateway with no mail server>
  6. #
  7. # (c) 2005 Anthony Minessale II
  8. # Anthony Minessale <anthm@freeswitch.org>
  9. #
  10. ################################################################################
  11. use Net::SMTP;
  12. my $relayhost = "localhost"; # what is the internet address of your smtp server
  13. my $over_from = ""; # define this to override the to
  14. my $over_to = ""; # define this to override the from
  15. my $debug = 0; # set to 1 to watch it deliver
  16. my $timeout = 60; # when to give up.
  17. ################################################################################
  18. $/ = undef;
  19. my $msg = <STDIN>;
  20. my ($to) = $over_to || $msg =~ /To: (.*)/;
  21. my ($from) = $over_from || $msg =~ /From: (.*)/;
  22. if($to =~ /<([^>]+)>/) {
  23. $to = $1;
  24. }
  25. if($from =~ /<([^>]+)>/) {
  26. $from = $1;
  27. }
  28. my $smtp = Net::SMTP->new($relayhost, Debug => $debug, Timeout => $timout);
  29. $smtp->mail($from);
  30. $smtp->to(split /,/, $to);
  31. $smtp->data($msg);
  32. $smtp->quit();