Perl Basics
Introduction to Perl
FAQ's
CGI
Regular Expressions

PC Overview
Cool Stuff
My Modules
Success Stories
Links
Perl in the News
Logos
Perl @ msn
Perl Chat

PC Internals
About
Contact
Guest Book
Handy Logos
What's new

Portable Version of Sending Mail without sendmail

FAQ's & Answers
See also
P-friendly

[ home ] - [ search ] - [ sitemap ]

Very flexible version. Runs on Windows and Unix.

#!/usr/local/bin/perl -w

use strict;
use Net::SMTP;
use Net::Config;

my $smtp_host = (@{$NetConfig{smtp_hosts}})[0];

print "$smtp_host\n";

# $smtp_host = "mail.bluewin.ch";

my $smtp = Net::SMTP->new($smtp_host, Debug => 0) or die "Could not create object";


sendmail(to => "you\@domain.ch", subject => 'test', msg => "Hello!\n");

sendmail(to => "another\@domain.com", subject => '2nd test', msg => "Hello again!\n");

$smtp->quit; 

sub sendmail(@) {

my %args = @_;

# return path
$smtp->mail('spam@insign.ch');
$smtp->to($args{'to'});

# mail message body
$smtp->data();
$smtp->datasend("From: you\@yourdomain.ch\n");
$smtp->datasend("To: friends_of_quasimodo\@yourdomain.ch\n");
$smtp->datasend("Subject: $args{'subject'}\n\n");

$smtp->datasend($args{'msg'});
$smtp->datasend("----- END OF MAIL -----\n");

$smtp->dataend() or die "Could not send";
} 
home - feedback - search - web jobs
© 1998-2004 retoh :)