in reply to Perl in Win32: How do I email form output?
Bookmark this it can be hard to find.
Net::SMTP will do the job... this below provides a basic wrapper for some admin scripts I use. N.B. recipient list would be better as an array reference.
sub send_mail_via_smtp() { ### Parameters my ($smtp_server, $recipient_list, $from, $subject, $body) = @_; ### Locals my $to_line = ''; my $smtp = ''; my @recipients = ''; my $recipient = ''; ### connect to SMTP server $smtp = Net::SMTP->new( $smtp_server, #Debug => 1, ) or die "send_mail_via_smtp(): Unable to connect to $smtp_server, +$!, Stopped"; $smtp->mail($from); @recipients = split(/,/, $recipient_list); foreach $recipient (@recipients) { $smtp->to($recipient); $to_line = $recipient . ',' . $to_line } $to_line =~ s/,$//; # Strip off any trailing ,'s ### Start the actual mail $smtp->data(); ### Header $smtp->datasend("To: $to_line\n"); $smtp->datasend("From: $from\n"); $smtp->datasend("Subject: $subject:\n"); $smtp->datasend("\n"); ### Body $smtp->datasend("$body\n"); ### Send $smtp->dataend(); $smtp->quit; }
|
|---|