#!/usr/bin/perl use warnings; use strict; use Net::SMTP; send_mail('hi', 'test-msg', ['stefan@example.com']); sub send_mail { my $sub = shift; my $msg = shift; my $to = shift; my $pid = fork(); if ( !defined $pid ) { die "Cannot fork: $!"; } elsif ( $pid == 0 ) { #child die "Recipients need to be array-ref." unless ref $to eq 'ARRAY'; my $smtp = Net::SMTP->new("mail.example.com", Port => 587, Debug => 1) or die $!; my $from = 'robot@example.com'; $smtp->starttls( SSL_verify_mode => 0 ); $smtp->auth('robot@example.com', 'PASS'); $smtp->mail($from); $smtp->to( @$to ); $smtp->data(); $smtp->datasend('Date: ' . localtime( time() ) . "\n" ); $smtp->datasend("From: $from\n"); $smtp->datasend('To: ' . join(',', @$to) . "\n"); $smtp->datasend("Subject: $sub\n"); $smtp->datasend("\n"); $smtp->datasend("$msg\n\n"); $smtp->dataend; $smtp->quit; exit 0; } }