Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Answer: How do I send e-mail from my Perl Program?

( #36544=categorized answer: print w/ replies, xml ) Need Help??

Q&A > mail and news > How do I send e-mail from my Perl Program? contributed by Adam

use strict; # ALWAYS! use Net::SMTP; # Yes, this will work on windows. # You need to fill in the variables. # Read the perldoc for more info on using SMTP. my $smtp = Net::SMTP->new('$mailserver_url') or die $!; $smtp->mail( $from ); $smtp->to( $to ); $smtp->data(); $smtp->datasend("To: $to\n"); $smtp->datasend("From: $from\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("\n"); # done with header $smtp->datasend($message); $smtp->dataend(); $smtp->quit(); # all done. message sent.

Comment on Answer: How do I send e-mail from my Perl Program?
Download Code
Replies are listed 'Best First'.
Re: Answer: How do I send e-mail from my Perl Program?
by cLive ;-) (Parson) on Jan 14, 2002 at 10:16 UTC
    Small error:
    my $smtp = Net::SMTP->new('$mailserver_url') or die $!;
    should be:
    my $smtp = Net::SMTP->new($mailserver_url) or die $!;
    or
    my $smtp = Net::SMTP->new("$mailserver_url") or die $!;
    Single quotes aren't interpolated!

    cLive ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2015-07-07 19:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls